home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 14 / CU Amiga Magazine's Super CD-ROM 14 (1997)(EMAP Images)(GB)(Track 1 of 3)[!][issue 1997-09].iso / CUCD / Programming / Mesa-2.2 / src / dlist.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-03-13  |  78.1 KB  |  3,164 lines

  1. /* $Id: dlist.c,v 1.12 1997/02/27 19:58:08 brianp Exp $ */
  2.  
  3. /*
  4.  * Mesa 3-D graphics library
  5.  * Version:  2.2
  6.  * Copyright (C) 1995-1997  Brian Paul
  7.  *
  8.  * This library is free software; you can redistribute it and/or
  9.  * modify it under the terms of the GNU Library General Public
  10.  * License as published by the Free Software Foundation; either
  11.  * version 2 of the License, or (at your option) any later version.
  12.  *
  13.  * This library is distributed in the hope that it will be useful,
  14.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16.  * Library General Public License for more details.
  17.  *
  18.  * You should have received a copy of the GNU Library General Public
  19.  * License along with this library; if not, write to the Free
  20.  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21.  */
  22.  
  23.  
  24. /*
  25.  * $Log: dlist.c,v $
  26.  * Revision 1.12  1997/02/27 19:58:08  brianp
  27.  * call gl_problem() instead of gl_warning()
  28.  *
  29.  * Revision 1.11  1997/02/09 18:50:18  brianp
  30.  * added GL_EXT_texture3D support
  31.  *
  32.  * Revision 1.10  1997/01/29 18:51:30  brianp
  33.  * small MEMCPY call change for Acorn compiler, per Graham Jones
  34.  *
  35.  * Revision 1.9  1997/01/09 21:25:28  brianp
  36.  * set reference count to one for texture images in display lists
  37.  *
  38.  * Revision 1.8  1996/12/11 20:19:11  brianp
  39.  * abort display list execution if invalid opcode found
  40.  *
  41.  * Revision 1.7  1996/12/09 21:39:23  brianp
  42.  * compare list to MAX_DISPLAYLISTS in gl_IsList()
  43.  *
  44.  * Revision 1.6  1996/12/04 22:14:27  brianp
  45.  * improved the mesa_print_display_list() debug function
  46.  *
  47.  * Revision 1.5  1996/11/07 04:12:45  brianp
  48.  * texture images are now gl_image structs, not gl_texture_image structs
  49.  *
  50.  * Revision 1.4  1996/10/16 00:59:12  brianp
  51.  * fixed bug in gl_save_Lightfv()
  52.  * execution of OPCODE_EDGE_FLAG used enum value instead of boolean
  53.  *
  54.  * Revision 1.3  1996/09/27 01:26:08  brianp
  55.  * removed unused variables
  56.  *
  57.  * Revision 1.2  1996/09/19 00:54:43  brianp
  58.  * fixed bug in gl_save_Rotatef() when in GL_COMPILE_AND_EXECUTE mode
  59.  *
  60.  * Revision 1.1  1996/09/13 01:38:16  brianp
  61.  * Initial revision
  62.  *
  63.  */
  64.  
  65.  
  66. #include <assert.h>
  67. #include <stdio.h>
  68. #include <stdlib.h>
  69. #include <string.h>
  70. #include "accum.h"
  71. #include "alpha.h"
  72. #include "attrib.h"
  73. #include "bitmap.h"
  74. #include "blend.h"
  75. #include "clip.h"
  76. #include "context.h"
  77. #include "copypix.h"
  78. #include "depth.h"
  79. #include "draw.h"
  80. #include "drawpix.h"
  81. #include "enable.h"
  82. #include "eval.h"
  83. #include "feedback.h"
  84. #include "fog.h"
  85. #include "image.h"
  86. #include "light.h"
  87. #include "lines.h"
  88. #include "dlist.h"
  89. #include "logic.h"
  90. #include "macros.h"
  91. #include "masking.h"
  92. #include "matrix.h"
  93. #include "misc.h"
  94. #include "pixel.h"
  95. #include "points.h"
  96. #include "polygon.h"
  97. #include "scissor.h"
  98. #include "stencil.h"
  99. #include "texobj.h"
  100. #include "teximage.h"
  101. #include "texture.h"
  102. #include "types.h"
  103. #include "vb.h"
  104. #include "vertex.h"
  105. #include "winpos.h"
  106.  
  107.  
  108.  
  109. #if 0
  110. #define EXEC(FUNC)  (*ctx->Exec.FUNC)
  111. #else
  112. #define EXEC(FUNC)  gl_##FUNC
  113. #endif
  114.  
  115.  
  116.  
  117.  
  118. /*
  119. Functions which aren't compiled but executed immediately:
  120.     glIsList
  121.     glGenLists
  122.     glDeleteLists
  123.     glEndList
  124.     glFeedbackBuffer
  125.     glSelectBuffer
  126.     glRenderMode
  127.     glReadPixels
  128.     glPixelStore
  129.     glFlush
  130.     glFinish
  131.     glIsEnabled
  132.     glGet*
  133.  
  134. Functions which cause errors if called while compiling a display list:
  135.     glNewList
  136. */
  137.  
  138.  
  139.  
  140. /*
  141.  * Display list instructions are stored as sequences of "nodes".  Nodes
  142.  * are allocated in blocks.  Each block has BLOCK_SIZE nodes.  Blocks
  143.  * are linked together with a pointer.
  144.  */
  145.  
  146.  
  147. /* How many nodes to allocate at a time: */
  148. #define BLOCK_SIZE 500
  149.  
  150.  
  151. /*
  152.  * Display list opcodes.
  153.  *
  154.  * The fact that these identifiers are assigned consecutive
  155.  * integer values starting at 0 is very important, see InstSize array usage)
  156.  */
  157. typedef enum {
  158.     OPCODE_ACCUM,
  159.     OPCODE_ALPHA_FUNC,
  160.         OPCODE_BEGIN,
  161.         OPCODE_BIND_TEXTURE,
  162.     OPCODE_BITMAP,
  163.     OPCODE_BLEND_COLOR,
  164.     OPCODE_BLEND_EQUATION,
  165.     OPCODE_BLEND_FUNC,
  166.         OPCODE_CALL_LIST,
  167.         OPCODE_CALL_LIST_OFFSET,
  168.     OPCODE_CLEAR,
  169.     OPCODE_CLEAR_ACCUM,
  170.     OPCODE_CLEAR_COLOR,
  171.     OPCODE_CLEAR_DEPTH,
  172.     OPCODE_CLEAR_INDEX,
  173.     OPCODE_CLEAR_STENCIL,
  174.         OPCODE_CLIP_PLANE,
  175.     OPCODE_COLOR_4F,
  176.     OPCODE_COLOR_4UB,
  177.     OPCODE_COLOR_MASK,
  178.     OPCODE_COLOR_MATERIAL,
  179.     OPCODE_COPY_PIXELS,
  180.         OPCODE_COPY_TEX_IMAGE1D,
  181.         OPCODE_COPY_TEX_IMAGE2D,
  182.         OPCODE_COPY_TEX_IMAGE3D,
  183.         OPCODE_COPY_TEX_SUB_IMAGE1D,
  184.         OPCODE_COPY_TEX_SUB_IMAGE2D,
  185.         OPCODE_COPY_TEX_SUB_IMAGE3D,
  186.     OPCODE_CULL_FACE,
  187.     OPCODE_DEPTH_FUNC,
  188.     OPCODE_DEPTH_MASK,
  189.     OPCODE_DEPTH_RANGE,
  190.     OPCODE_DISABLE,
  191.     OPCODE_DRAW_BUFFER,
  192.     OPCODE_DRAW_PIXELS,
  193.         OPCODE_EDGE_FLAG,
  194.     OPCODE_ENABLE,
  195.         OPCODE_END,
  196.     OPCODE_EVALCOORD1,
  197.     OPCODE_EVALCOORD2,
  198.     OPCODE_EVALMESH1,
  199.     OPCODE_EVALMESH2,
  200.     OPCODE_EVALPOINT1,
  201.     OPCODE_EVALPOINT2,
  202.     OPCODE_FOG,
  203.     OPCODE_FRONT_FACE,
  204.     OPCODE_FRUSTUM,
  205.     OPCODE_HINT,
  206.     OPCODE_INDEX,
  207.     OPCODE_INDEX_MASK,
  208.     OPCODE_INIT_NAMES,
  209.     OPCODE_LIGHT,
  210.     OPCODE_LIGHT_MODEL,
  211.     OPCODE_LINE_STIPPLE,
  212.     OPCODE_LINE_WIDTH,
  213.     OPCODE_LIST_BASE,
  214.     OPCODE_LOAD_MATRIX,
  215.     OPCODE_LOAD_NAME,
  216.     OPCODE_LOGIC_OP,
  217.     OPCODE_MAP1,
  218.     OPCODE_MAP2,
  219.     OPCODE_MAPGRID1,
  220.     OPCODE_MAPGRID2,
  221.     OPCODE_MATERIAL,
  222.     OPCODE_MATRIX_MODE,
  223.     OPCODE_MULT_MATRIX,
  224.         OPCODE_NORMAL,
  225.     OPCODE_PASSTHROUGH,
  226.     OPCODE_PIXEL_MAP,
  227.     OPCODE_PIXEL_TRANSFER,
  228.     OPCODE_PIXEL_ZOOM,
  229.     OPCODE_POINTSIZE,
  230.     OPCODE_POLYGON_MODE,
  231.         OPCODE_POLYGON_STIPPLE,
  232.     OPCODE_POLYGON_OFFSET,
  233.     OPCODE_POP_ATTRIB,
  234.     OPCODE_POP_MATRIX,
  235.     OPCODE_POP_NAME,
  236.     OPCODE_PRIORITIZE_TEXTURE,
  237.     OPCODE_PUSH_ATTRIB,
  238.     OPCODE_PUSH_MATRIX,
  239.     OPCODE_PUSH_NAME,
  240.     OPCODE_RASTER_POS,
  241.     OPCODE_READ_BUFFER,
  242.         OPCODE_SCALE,
  243.     OPCODE_SCISSOR,
  244.     OPCODE_SHADE_MODEL,
  245.     OPCODE_STENCIL_FUNC,
  246.     OPCODE_STENCIL_MASK,
  247.     OPCODE_STENCIL_OP,
  248.     OPCODE_TEXCOORD,
  249.         OPCODE_TEXENV,
  250.         OPCODE_TEXGEN,
  251.         OPCODE_TEXPARAMETER,
  252.     OPCODE_TEX_IMAGE1D,
  253.     OPCODE_TEX_IMAGE2D,
  254.     OPCODE_TEX_IMAGE3D,
  255.     OPCODE_TEX_SUB_IMAGE1D,
  256.     OPCODE_TEX_SUB_IMAGE2D,
  257.     OPCODE_TEX_SUB_IMAGE3D,
  258.         OPCODE_TRANSLATE,
  259.         OPCODE_VERTEX,
  260.     OPCODE_VIEWPORT,
  261.     OPCODE_WINDOW_POS,
  262.     /* The following two are meta instructions */
  263.     OPCODE_CONTINUE,
  264.     OPCODE_END_OF_LIST
  265. } OpCode;
  266.  
  267.  
  268. /*
  269.  * Each instruction in the display list is stored as a sequence of
  270.  * contiguous nodes in memory.
  271.  * Each node is the union of a variety of datatypes.
  272.  */
  273. typedef union node {
  274.     OpCode        opcode;
  275.     GLboolean    b;
  276.     GLbitfield    bf;
  277.     GLubyte        ub;
  278.     GLshort        s;
  279.     GLushort    us;
  280.     GLint        i;
  281.     GLuint        ui;
  282.     GLenum        e;
  283.     GLfloat        f;
  284.     GLvoid        *data;
  285.     void        *next;    /* If prev node's opcode==OPCODE_CONTINUE */
  286. } Node;
  287.  
  288.  
  289.  
  290. /* Number of nodes of storage needed for each instruction: */
  291. static GLuint InstSize[ OPCODE_END_OF_LIST+1 ];
  292.  
  293.  
  294. /* Used while a display list is under construction: */
  295. static Node *CurrentListPtr;    /* Head of list being compiled */
  296. static GLuint CurrentListNum;    /* Number of the list being compiled */
  297. static Node *CurrentBlock;    /* Pointer to current block of nodes */
  298. static GLuint CurrentPos;    /* Index into current block of nodes */
  299.  
  300.  
  301.  
  302.  
  303. /**********************************************************************/
  304. /*****                           Private                          *****/
  305. /**********************************************************************/
  306.  
  307.  
  308. /*
  309.  * Allocate space for a display list instruction.
  310.  * Input:  opcode - type of instruction
  311.  *         argcount - number of arguments following the instruction
  312.  * Return: pointer to first node in the instruction
  313.  */
  314. static Node *alloc_instruction( GLcontext *ctx, OpCode opcode, GLint argcount )
  315. {
  316.    Node *n, *newblock;
  317.    GLuint count = InstSize[opcode];
  318.  
  319.    assert( count == argcount+1 );
  320.  
  321.    if (CurrentPos + count + 2 > BLOCK_SIZE) {
  322.       /* This block is full.  Allocate a new block and chain to it */
  323.       n = CurrentBlock + CurrentPos;
  324.       n[0].opcode = OPCODE_CONTINUE;
  325.       newblock = (Node *) malloc( sizeof(Node) * BLOCK_SIZE );
  326.       if (!newblock) {
  327.          gl_error( ctx, GL_OUT_OF_MEMORY, "Building display list" );
  328.          return NULL;
  329.       }
  330.       n[1].next = (Node *) newblock;
  331.       CurrentBlock = newblock;
  332.       CurrentPos = 0;
  333.    }
  334.  
  335.    n = CurrentBlock + CurrentPos;
  336.    CurrentPos += count;
  337.  
  338.    n[0].opcode = opcode;
  339.  
  340.    return n;
  341. }
  342.  
  343.  
  344.  
  345. /*
  346.  * Make an empty display list.  This is used by glGenLists() to
  347.  * reserver display list IDs.
  348.  */
  349. static Node *make_empty_list( void )
  350. {
  351.    Node *n = (Node *) malloc( sizeof(Node) );
  352.    n[0].opcode = OPCODE_END_OF_LIST;
  353.    return n;
  354. }
  355.  
  356.  
  357.  
  358. /*
  359.  * Destroy all nodes in a display list.
  360.  * Input:  list - list number in [0..]
  361.  */
  362. static void destroy_list( GLcontext *ctx, GLuint list )
  363. {
  364.    Node *n, *block;
  365.    GLboolean done;
  366.  
  367.    block = n = ctx->Shared->List[list];
  368.  
  369.    done = GL_FALSE;
  370.    while (!done) {
  371.       switch (n[0].opcode) {
  372.      /* special cases first */
  373.      case OPCODE_MAP1:
  374.         gl_free_control_points( ctx, n[1].e, (GLfloat *) n[6].data );
  375.         n += InstSize[n[0].opcode];
  376.         break;
  377.      case OPCODE_MAP2:
  378.         gl_free_control_points( ctx, n[1].e, (GLfloat *) n[10].data );
  379.         n += InstSize[n[0].opcode];
  380.         break;
  381.      case OPCODE_DRAW_PIXELS:
  382.         free( n[5].data );
  383.         n += InstSize[n[0].opcode];
  384.         break;
  385.      case OPCODE_BITMAP:
  386.         gl_free_image( (struct gl_image *) n[7].data );
  387.         n += InstSize[n[0].opcode];
  388.         break;
  389.          case OPCODE_POLYGON_STIPPLE:
  390.             free( n[1].data );
  391.         n += InstSize[n[0].opcode];
  392.             break;
  393.      case OPCODE_TEX_IMAGE1D:
  394.             gl_free_image( (struct gl_image *) n[8].data );
  395.             n += InstSize[n[0].opcode];
  396.         break;
  397.      case OPCODE_TEX_IMAGE2D:
  398.             gl_free_image( (struct gl_image *) n[9].data );
  399.             n += InstSize[n[0].opcode];
  400.         break;
  401.          case OPCODE_TEX_SUB_IMAGE1D:
  402.             {
  403.                struct gl_image *image;
  404.                image = (struct gl_image *) n[7].data;
  405.                gl_free_image( image );
  406.             }
  407.             break;
  408.          case OPCODE_TEX_SUB_IMAGE2D:
  409.             {
  410.                struct gl_image *image;
  411.                image = (struct gl_image *) n[9].data;
  412.                gl_free_image( image );
  413.             }
  414.             break;
  415.      case OPCODE_CONTINUE:
  416.         n = (Node *) n[1].next;
  417.         free( block );
  418.         block = n;
  419.         break;
  420.      case OPCODE_END_OF_LIST:
  421.         free( block );
  422.         done = GL_TRUE;
  423.         break;
  424.      default:
  425.         /* Most frequent case */
  426.         n += InstSize[n[0].opcode];
  427.         break;
  428.       }
  429.    }
  430.  
  431.    ctx->Shared->List[list] = NULL;
  432. }
  433.  
  434.  
  435.  
  436. /*
  437.  * Translate the nth element of list from type to GLuint.
  438.  */
  439. static GLuint translate_id( GLsizei n, GLenum type, const GLvoid *list )
  440. {
  441.    GLbyte *bptr;
  442.    GLubyte *ubptr;
  443.    GLshort *sptr;
  444.    GLushort *usptr;
  445.    GLint *iptr;
  446.    GLuint *uiptr;
  447.    GLfloat *fptr;
  448.  
  449.    switch (type) {
  450.       case GL_BYTE:
  451.          bptr = (GLbyte *) list;
  452.          return (GLuint) *(bptr+n);
  453.       case GL_UNSIGNED_BYTE:
  454.          ubptr = (GLubyte *) list;
  455.          return (GLuint) *(ubptr+n);
  456.       case GL_SHORT:
  457.          sptr = (GLshort *) list;
  458.          return (GLuint) *(sptr+n);
  459.       case GL_UNSIGNED_SHORT:
  460.          usptr = (GLushort *) list;
  461.          return (GLuint) *(usptr+n);
  462.       case GL_INT:
  463.          iptr = (GLint *) list;
  464.          return (GLuint) *(iptr+n);
  465.       case GL_UNSIGNED_INT:
  466.          uiptr = (GLuint *) list;
  467.          return (GLuint) *(uiptr+n);
  468.       case GL_FLOAT:
  469.          fptr = (GLfloat *) list;
  470.          return (GLuint) *(fptr+n);
  471.       case GL_2_BYTES:
  472.          ubptr = ((GLubyte *) list) + 2*n;
  473.          return (GLuint) *ubptr * 256 + (GLuint) *(ubptr+1);
  474.       case GL_3_BYTES:
  475.          ubptr = ((GLubyte *) list) + 3*n;
  476.          return (GLuint) *ubptr * 65536
  477.               + (GLuint) *(ubptr+1) * 256
  478.               + (GLuint) *(ubptr+2);
  479.       case GL_4_BYTES:
  480.          ubptr = ((GLubyte *) list) + 4*n;
  481.          return (GLuint) *ubptr * 16777216
  482.               + (GLuint) *(ubptr+1) * 65536
  483.               + (GLuint) *(ubptr+2) * 256
  484.               + (GLuint) *(ubptr+3);
  485.       default:
  486.          return 0;
  487.    }
  488. }
  489.  
  490.  
  491.  
  492.  
  493. /**********************************************************************/
  494. /*****                        Public                              *****/
  495. /**********************************************************************/
  496.  
  497. void gl_init_lists( void )
  498. {
  499.    static int init_flag = 0;
  500.  
  501.    if (init_flag==0) {
  502.       CurrentListPtr = CurrentBlock = NULL;
  503.       CurrentListNum = 0;
  504.  
  505.       InstSize[OPCODE_ACCUM] = 3;
  506.       InstSize[OPCODE_ALPHA_FUNC] = 3;
  507.       InstSize[OPCODE_BEGIN] = 2;
  508.       InstSize[OPCODE_BIND_TEXTURE] = 3;
  509.       InstSize[OPCODE_BITMAP] = 8;
  510.       InstSize[OPCODE_BLEND_COLOR] = 5;
  511.       InstSize[OPCODE_BLEND_EQUATION] = 2;
  512.       InstSize[OPCODE_BLEND_FUNC] = 3;
  513.       InstSize[OPCODE_CALL_LIST] = 2;
  514.       InstSize[OPCODE_CALL_LIST_OFFSET] = 2;
  515.       InstSize[OPCODE_CLEAR] = 2;
  516.       InstSize[OPCODE_CLEAR_ACCUM] = 5;
  517.       InstSize[OPCODE_CLEAR_COLOR] = 5;
  518.       InstSize[OPCODE_CLEAR_DEPTH] = 2;
  519.       InstSize[OPCODE_CLEAR_INDEX] = 2;
  520.       InstSize[OPCODE_CLEAR_STENCIL] = 2;
  521.       InstSize[OPCODE_CLIP_PLANE] = 6;
  522.       InstSize[OPCODE_COLOR_4F] = 5;
  523.       InstSize[OPCODE_COLOR_4UB] = 5;
  524.       InstSize[OPCODE_COLOR_MASK] = 5;
  525.       InstSize[OPCODE_COLOR_MATERIAL] = 3;
  526.       InstSize[OPCODE_COPY_PIXELS] = 6;
  527.       InstSize[OPCODE_COPY_TEX_IMAGE1D] = 8;
  528.       InstSize[OPCODE_COPY_TEX_IMAGE2D] = 9;
  529.       InstSize[OPCODE_COPY_TEX_SUB_IMAGE1D] = 7;
  530.       InstSize[OPCODE_COPY_TEX_SUB_IMAGE2D] = 9;
  531.       InstSize[OPCODE_COPY_TEX_SUB_IMAGE3D] = 10;
  532.       InstSize[OPCODE_CULL_FACE] = 2;
  533.       InstSize[OPCODE_DEPTH_FUNC] = 2;
  534.       InstSize[OPCODE_DEPTH_MASK] = 2;
  535.       InstSize[OPCODE_DEPTH_RANGE] = 3;
  536.       InstSize[OPCODE_DISABLE] = 2;
  537.       InstSize[OPCODE_DRAW_BUFFER] = 2;
  538.       InstSize[OPCODE_DRAW_PIXELS] = 6;
  539.       InstSize[OPCODE_ENABLE] = 2;
  540.       InstSize[OPCODE_EDGE_FLAG] = 2;
  541.       InstSize[OPCODE_END] = 1;
  542.       InstSize[OPCODE_EVALCOORD1] = 2;
  543.       InstSize[OPCODE_EVALCOORD2] = 3;
  544.       InstSize[OPCODE_EVALMESH1] = 4;
  545.       InstSize[OPCODE_EVALMESH2] = 6;
  546.       InstSize[OPCODE_EVALPOINT1] = 2;
  547.       InstSize[OPCODE_EVALPOINT2] = 3;
  548.       InstSize[OPCODE_FOG] = 6;
  549.       InstSize[OPCODE_FRONT_FACE] = 2;
  550.       InstSize[OPCODE_FRUSTUM] = 7;
  551.       InstSize[OPCODE_HINT] = 3;
  552.       InstSize[OPCODE_INDEX] = 2;
  553.       InstSize[OPCODE_INDEX_MASK] = 2;
  554.       InstSize[OPCODE_INIT_NAMES] = 1;
  555.       InstSize[OPCODE_LIGHT] = 7;
  556.       InstSize[OPCODE_LIGHT_MODEL] = 6;
  557.       InstSize[OPCODE_LINE_STIPPLE] = 3;
  558.       InstSize[OPCODE_LINE_WIDTH] = 2;
  559.       InstSize[OPCODE_LIST_BASE] = 2;
  560.       InstSize[OPCODE_LOAD_MATRIX] = 17;
  561.       InstSize[OPCODE_LOAD_NAME] = 2;
  562.       InstSize[OPCODE_LOGIC_OP] = 2;
  563.       InstSize[OPCODE_MAP1] = 7;
  564.       InstSize[OPCODE_MAP2] = 11;
  565.       InstSize[OPCODE_MAPGRID1] = 4;
  566.       InstSize[OPCODE_MAPGRID2] = 7;
  567.       InstSize[OPCODE_MATERIAL] = 7;
  568.       InstSize[OPCODE_MATRIX_MODE] = 2;
  569.       InstSize[OPCODE_MULT_MATRIX] = 17;
  570.       InstSize[OPCODE_NORMAL] = 4;
  571.       InstSize[OPCODE_PASSTHROUGH] = 2;
  572.       InstSize[OPCODE_PIXEL_MAP] = 4;
  573.       InstSize[OPCODE_PIXEL_TRANSFER] = 3;
  574.       InstSize[OPCODE_PIXEL_ZOOM] = 3;
  575.       InstSize[OPCODE_POINTSIZE] = 2;
  576.       InstSize[OPCODE_POLYGON_MODE] = 3;
  577.       InstSize[OPCODE_POLYGON_STIPPLE] = 2;
  578.       InstSize[OPCODE_POLYGON_OFFSET] = 3;
  579.       InstSize[OPCODE_POP_ATTRIB] = 1;
  580.       InstSize[OPCODE_POP_MATRIX] = 1;
  581.       InstSize[OPCODE_POP_NAME] = 1;
  582.       InstSize[OPCODE_PRIORITIZE_TEXTURE] = 3;
  583.       InstSize[OPCODE_PUSH_ATTRIB] = 2;
  584.       InstSize[OPCODE_PUSH_MATRIX] = 1;
  585.       InstSize[OPCODE_PUSH_NAME] = 2;
  586.       InstSize[OPCODE_RASTER_POS] = 5;
  587.       InstSize[OPCODE_READ_BUFFER] = 2;
  588.       InstSize[OPCODE_SCALE] = 4;
  589.       InstSize[OPCODE_SCISSOR] = 5;
  590.       InstSize[OPCODE_STENCIL_FUNC] = 4;
  591.       InstSize[OPCODE_STENCIL_MASK] = 2;
  592.       InstSize[OPCODE_STENCIL_OP] = 4;
  593.       InstSize[OPCODE_SHADE_MODEL] = 2;
  594.       InstSize[OPCODE_TEXCOORD] = 5;
  595.       InstSize[OPCODE_TEXENV] = 7;
  596.       InstSize[OPCODE_TEXGEN] = 7;
  597.       InstSize[OPCODE_TEXPARAMETER] = 7;
  598.       InstSize[OPCODE_TEX_IMAGE1D] = 9;
  599.       InstSize[OPCODE_TEX_IMAGE2D] = 10;
  600.       InstSize[OPCODE_TEX_IMAGE3D] = 11;
  601.       InstSize[OPCODE_TEX_SUB_IMAGE1D] = 8;
  602.       InstSize[OPCODE_TEX_SUB_IMAGE2D] = 10;
  603.       InstSize[OPCODE_TEX_SUB_IMAGE3D] = 12;
  604.       InstSize[OPCODE_TRANSLATE] = 4;
  605.       InstSize[OPCODE_VERTEX] = 5;
  606.       InstSize[OPCODE_VIEWPORT] = 5;
  607.       InstSize[OPCODE_WINDOW_POS] = 5;
  608.       InstSize[OPCODE_CONTINUE] = 2;
  609.       InstSize[OPCODE_END_OF_LIST] = 1;
  610.    }
  611.    init_flag = 1;
  612. }
  613.  
  614.  
  615.  
  616. /*
  617.  * Return the name of the display list currently being compiled.  This
  618.  * function is only called by glGet().
  619.  */
  620. GLint gl_list_index( void )
  621. {
  622.    return CurrentListNum;
  623. }
  624.  
  625.  
  626.  
  627. /*
  628.  * Display List compilation functions
  629.  */
  630.  
  631.  
  632. void gl_save_Accum( GLcontext *ctx, GLenum op, GLfloat value )
  633. {
  634.    Node *n = alloc_instruction( ctx, OPCODE_ACCUM, 2 );
  635.    if (n) {
  636.       n[1].e = op;
  637.       n[2].f = value;
  638.    }
  639.    if (ctx->ExecuteFlag) {
  640.       EXEC(Accum)( ctx, op, value );
  641.    }
  642. }
  643.  
  644.  
  645. void gl_save_AlphaFunc( GLcontext *ctx, GLenum func, GLclampf ref )
  646. {
  647.    Node *n = alloc_instruction( ctx, OPCODE_ALPHA_FUNC, 2 );
  648.    if (n) {
  649.       n[1].e = func;
  650.       n[2].f = (GLfloat) ref;
  651.    }
  652.    if (ctx->ExecuteFlag) {
  653.       EXEC(AlphaFunc)( ctx, func, ref );
  654.    }
  655. }
  656.  
  657.  
  658. void gl_save_Begin( GLcontext *ctx, GLenum mode )
  659. {
  660.    Node *n = alloc_instruction( ctx, OPCODE_BEGIN, 1 );
  661.    if (n) {
  662.       n[1].e = mode;
  663.    }
  664.    if (ctx->ExecuteFlag) {
  665.       EXEC(Begin)( ctx, mode );
  666.    }
  667. }
  668.  
  669.  
  670. void gl_save_BindTexture( GLcontext *ctx, GLenum target, GLuint texture )
  671. {
  672.    Node *n = alloc_instruction( ctx, OPCODE_BIND_TEXTURE, 2 );
  673.    if (n) {
  674.       n[1].e = target;
  675.       n[2].ui = texture;
  676.    }
  677.    if (ctx->ExecuteFlag) {
  678.       EXEC(BindTexture)( ctx, target, texture );
  679.    }
  680. }
  681.  
  682.  
  683. void gl_save_Bitmap( GLcontext *ctx,
  684.                      GLsizei width, GLsizei height,
  685.              GLfloat xorig, GLfloat yorig,
  686.              GLfloat xmove, GLfloat ymove,
  687.              const struct gl_image *bitmap )
  688. {
  689.    Node *n = alloc_instruction( ctx, OPCODE_BITMAP, 7 );
  690.    if (n) {
  691.       n[1].i = (GLint) width;
  692.       n[2].i = (GLint) height;
  693.       n[3].f = xorig;
  694.       n[4].f = yorig;
  695.       n[5].f = xmove;
  696.       n[6].f = ymove;
  697.       n[7].data = (void *) bitmap;
  698.    }
  699.    if (ctx->ExecuteFlag) {
  700.       EXEC(Bitmap)( ctx, width, height,
  701.                     xorig, yorig, xmove, ymove, bitmap );
  702.    }
  703. }
  704.  
  705.  
  706. void gl_save_BlendEquation( GLcontext *ctx, GLenum mode )
  707. {
  708.    Node *n = alloc_instruction( ctx, OPCODE_BLEND_EQUATION, 1 );
  709.    if (n) {
  710.       n[1].e = mode;
  711.    }
  712.    if (ctx->ExecuteFlag) {
  713.       EXEC(BlendEquation)( ctx, mode );
  714.    }
  715. }
  716.  
  717.  
  718. void gl_save_BlendFunc( GLcontext *ctx, GLenum sfactor, GLenum dfactor )
  719. {
  720.    Node *n = alloc_instruction( ctx, OPCODE_BLEND_FUNC, 2 );
  721.    if (n) {
  722.       n[1].e = sfactor;
  723.       n[2].e = dfactor;
  724.    }
  725.    if (ctx->ExecuteFlag) {
  726.       EXEC(BlendFunc)( ctx, sfactor, dfactor );
  727.    }
  728. }
  729.  
  730.  
  731. void gl_save_BlendColor( GLcontext *ctx, GLfloat red, GLfloat green,
  732.                          GLfloat blue, GLfloat alpha )
  733. {
  734.    Node *n = alloc_instruction( ctx, OPCODE_BLEND_COLOR, 4 );
  735.    if (n) {
  736.       n[1].f = red;
  737.       n[2].f = green;
  738.       n[3].f = blue;
  739.       n[4].f = alpha;
  740.    }
  741.    if (ctx->ExecuteFlag) {
  742.       EXEC(BlendColor)( ctx, red, green, blue, alpha );
  743.    }
  744. }
  745.  
  746.  
  747. void gl_save_CallList( GLcontext *ctx, GLuint list )
  748. {
  749.    Node *n = alloc_instruction( ctx, OPCODE_CALL_LIST, 1 );
  750.    if (n) {
  751.       n[1].ui = list;
  752.    }
  753.    if (ctx->ExecuteFlag) {
  754.       EXEC(CallList)( ctx, list );
  755.    }
  756. }
  757.  
  758.  
  759. void gl_save_CallLists( GLcontext *ctx,
  760.                         GLsizei n, GLenum type, const GLvoid *lists )
  761. {
  762.    GLuint i;
  763.  
  764.    for (i=0;i<n;i++) {
  765.       GLuint list = translate_id( i, type, lists );
  766.       Node *n = alloc_instruction( ctx, OPCODE_CALL_LIST_OFFSET, 1 );
  767.       if (n) {
  768.          n[1].ui = list;
  769.       }
  770.    }
  771.    if (ctx->ExecuteFlag) {
  772.       EXEC(CallLists)( ctx, n, type, lists );
  773.    }
  774. }
  775.  
  776.  
  777. void gl_save_Clear( GLcontext *ctx, GLbitfield mask )
  778. {
  779.    Node *n = alloc_instruction( ctx, OPCODE_CLEAR, 1 );
  780.    if (n) {
  781.       n[1].bf = mask;
  782.    }
  783.    if (ctx->ExecuteFlag) {
  784.       EXEC(Clear)( ctx, mask );
  785.    }
  786. }
  787.  
  788.  
  789. void gl_save_ClearAccum( GLcontext *ctx, GLfloat red, GLfloat green,
  790.              GLfloat blue, GLfloat alpha )
  791. {
  792.    Node *n = alloc_instruction( ctx, OPCODE_CLEAR_ACCUM, 4 );
  793.    if (n) {
  794.       n[1].f = red;
  795.       n[2].f = green;
  796.       n[3].f = blue;
  797.       n[4].f = alpha;
  798.    }
  799.    if (ctx->ExecuteFlag) {
  800.       EXEC(ClearAccum)( ctx, red, green, blue, alpha );
  801.    }
  802. }
  803.  
  804.  
  805. void gl_save_ClearColor( GLcontext *ctx, GLclampf red, GLclampf green,
  806.              GLclampf blue, GLclampf alpha )
  807. {
  808.    Node *n = alloc_instruction( ctx, OPCODE_CLEAR_COLOR, 4 );
  809.    if (n) {
  810.       n[1].f = red;
  811.       n[2].f = green;
  812.       n[3].f = blue;
  813.       n[4].f = alpha;
  814.    }
  815.    if (ctx->ExecuteFlag) {
  816.       EXEC(ClearColor)( ctx, red, green, blue, alpha );
  817.    }
  818. }
  819.  
  820.  
  821. void gl_save_ClearDepth( GLcontext *ctx, GLclampd depth )
  822. {
  823.    Node *n = alloc_instruction( ctx, OPCODE_CLEAR_DEPTH, 1 );
  824.    if (n) {
  825.       n[1].f = (GLfloat) depth;
  826.    }
  827.    if (ctx->ExecuteFlag) {
  828.       EXEC(ClearDepth)( ctx, depth );
  829.    }
  830. }
  831.  
  832.  
  833. void gl_save_ClearIndex( GLcontext *ctx, GLfloat c )
  834. {
  835.    Node *n = alloc_instruction( ctx, OPCODE_CLEAR_INDEX, 1 );
  836.    if (n) {
  837.       n[1].f = c;
  838.    }
  839.    if (ctx->ExecuteFlag) {
  840.       EXEC(ClearIndex)( ctx, c );
  841.    }
  842. }
  843.  
  844.  
  845. void gl_save_ClearStencil( GLcontext *ctx, GLint s )
  846. {
  847.    Node *n = alloc_instruction( ctx, OPCODE_CLEAR_STENCIL, 1 );
  848.    if (n) {
  849.       n[1].i = s;
  850.    }
  851.    if (ctx->ExecuteFlag) {
  852.       EXEC(ClearStencil)( ctx, s );
  853.    }
  854. }
  855.  
  856.  
  857. void gl_save_ClipPlane( GLcontext *ctx, GLenum plane, const GLfloat *equ )
  858. {
  859.    Node *n = alloc_instruction( ctx, OPCODE_CLIP_PLANE, 5 );
  860.    if (n) {
  861.       n[1].e = plane;
  862.       n[2].f = equ[0];
  863.       n[3].f = equ[1];
  864.       n[4].f = equ[2];
  865.       n[5].f = equ[3];
  866.    }
  867.    if (ctx->ExecuteFlag) {
  868.       EXEC(ClipPlane)( ctx, plane, equ );
  869.    }
  870. }
  871.  
  872.  
  873. void gl_save_Color4f( GLcontext *ctx, GLfloat r, GLfloat g,
  874.                                       GLfloat b, GLfloat a )
  875. {
  876.    Node *n = alloc_instruction( ctx, OPCODE_COLOR_4F, 4 );
  877.    if (n) {
  878.       n[1].f = r;
  879.       n[2].f = g;
  880.       n[3].f = b;
  881.       n[4].f = a;
  882.    }
  883.    if (ctx->ExecuteFlag) {
  884.       EXEC(Color4f)( ctx, r, g, b, a );
  885.    }
  886. }
  887.  
  888.  
  889. void gl_save_Color4ub( GLcontext *ctx, GLubyte r, GLubyte g,
  890.                                        GLubyte b, GLubyte a )
  891. {
  892.    Node *n = alloc_instruction( ctx, OPCODE_COLOR_4UB, 4 );
  893.    if (n) {
  894.       n[1].ub = r;
  895.       n[2].ub = g;
  896.       n[3].ub = b;
  897.       n[4].ub = a;
  898.    }
  899.    if (ctx->ExecuteFlag) {
  900.       EXEC(Color4ub)( ctx, r, g, b, a );
  901.    }
  902. }
  903.  
  904.  
  905. void gl_save_ColorMask( GLcontext *ctx, GLboolean red, GLboolean green,
  906.                         GLboolean blue, GLboolean alpha )
  907. {
  908.    Node *n = alloc_instruction( ctx, OPCODE_COLOR_MASK, 4 );
  909.    if (n) {
  910.       n[1].b = red;
  911.       n[2].b = green;
  912.       n[3].b = blue;
  913.       n[4].b = alpha;
  914.    }
  915.    if (ctx->ExecuteFlag) {
  916.       EXEC(ColorMask)( ctx, red, green, blue, alpha );
  917.    }
  918. }
  919.  
  920.  
  921. void gl_save_ColorMaterial( GLcontext *ctx, GLenum face, GLenum mode )
  922. {
  923.    Node *n = alloc_instruction( ctx, OPCODE_COLOR_MATERIAL, 2 );
  924.    if (n) {
  925.       n[1].e = face;
  926.       n[2].e = mode;
  927.    }
  928.    if (ctx->ExecuteFlag) {
  929.       EXEC(ColorMaterial)( ctx, face, mode );
  930.    }
  931. }
  932.  
  933.  
  934. void gl_save_CopyPixels( GLcontext *ctx, GLint x, GLint y,
  935.              GLsizei width, GLsizei height, GLenum type )
  936. {
  937.    Node *n = alloc_instruction( ctx, OPCODE_COPY_PIXELS, 5 );
  938.    if (n) {
  939.       n[1].i = x;
  940.       n[2].i = y;
  941.       n[3].i = (GLint) width;
  942.       n[4].i = (GLint) height;
  943.       n[5].e = type;
  944.    }
  945.    if (ctx->ExecuteFlag) {
  946.       EXEC(CopyPixels)( ctx, x, y, width, height, type );
  947.    }
  948. }
  949.  
  950.  
  951.  
  952. void gl_save_CopyTexImage1D( GLcontext *ctx,
  953.                              GLenum target, GLint level,
  954.                              GLenum internalformat,
  955.                              GLint x, GLint y, GLsizei width,
  956.                              GLint border )
  957. {
  958.    Node *n = alloc_instruction( ctx, OPCODE_COPY_TEX_IMAGE1D, 7 );
  959.    if (n) {
  960.       n[1].e = target;
  961.       n[2].i = level;
  962.       n[3].e = internalformat;
  963.       n[4].i = x;
  964.       n[5].i = y;
  965.       n[6].i = width;
  966.       n[7].i = border;
  967.    }
  968.    if (ctx->ExecuteFlag) {
  969.       EXEC(CopyTexImage1D)( ctx, target, level, internalformat,
  970.                             x, y, width, border );
  971.    }
  972. }
  973.  
  974.  
  975. void gl_save_CopyTexImage2D( GLcontext *ctx,
  976.                              GLenum target, GLint level,
  977.                              GLenum internalformat,
  978.                              GLint x, GLint y, GLsizei width,
  979.                              GLsizei height, GLint border )
  980. {
  981.    Node *n = alloc_instruction( ctx, OPCODE_COPY_TEX_IMAGE2D, 8 );
  982.    if (n) {
  983.       n[1].e = target;
  984.       n[2].i = level;
  985.       n[3].e = internalformat;
  986.       n[4].i = x;
  987.       n[5].i = y;
  988.       n[6].i = width;
  989.       n[7].i = height;
  990.       n[8].i = border;
  991.    }
  992.    if (ctx->ExecuteFlag) {
  993.       EXEC(CopyTexImage2D)( ctx, target, level, internalformat,
  994.                             x, y, width, height, border );
  995.    }
  996. }
  997.  
  998.  
  999.  
  1000. void gl_save_CopyTexSubImage1D( GLcontext *ctx,
  1001.                                 GLenum target, GLint level,
  1002.                                 GLint xoffset, GLint x, GLint y,
  1003.                                 GLsizei width )
  1004. {
  1005.    Node *n = alloc_instruction( ctx, OPCODE_COPY_TEX_SUB_IMAGE1D, 6 );
  1006.    if (n) {
  1007.       n[1].e = target;
  1008.       n[2].i = level;
  1009.       n[3].i = xoffset;
  1010.       n[4].i = x;
  1011.       n[5].i = y;
  1012.       n[6].i = width;
  1013.    }
  1014.    if (ctx->ExecuteFlag) {
  1015.       EXEC(CopyTexSubImage1D)( ctx, target, level, xoffset, x, y, width );
  1016.    }
  1017. }
  1018.  
  1019.  
  1020. void gl_save_CopyTexSubImage2D( GLcontext *ctx,
  1021.                                 GLenum target, GLint level,
  1022.                                 GLint xoffset, GLint yoffset,
  1023.                                 GLint x, GLint y,
  1024.                                 GLsizei width, GLint height )
  1025. {
  1026.    Node *n = alloc_instruction( ctx, OPCODE_COPY_TEX_SUB_IMAGE2D, 8 );
  1027.    if (n) {
  1028.       n[1].e = target;
  1029.       n[2].i = level;
  1030.       n[3].i = xoffset;
  1031.       n[4].i = yoffset;
  1032.       n[5].i = x;
  1033.       n[6].i = y;
  1034.       n[7].i = width;
  1035.       n[8].i = height;
  1036.    }
  1037.    if (ctx->ExecuteFlag) {
  1038.       EXEC(CopyTexSubImage2D)( ctx, target, level, xoffset, yoffset,
  1039.                                x, y, width, height );
  1040.    }
  1041. }
  1042.  
  1043.  
  1044. void gl_save_CopyTexSubImage3DEXT( GLcontext *ctx,
  1045.                                    GLenum target, GLint level,
  1046.                                    GLint xoffset, GLint yoffset, GLint zoffset,
  1047.                                    GLint x, GLint y,
  1048.                                    GLsizei width, GLint height )
  1049. {
  1050.    Node *n = alloc_instruction( ctx, OPCODE_COPY_TEX_SUB_IMAGE3D, 9 );
  1051.    if (n) {
  1052.       n[1].e = target;
  1053.       n[2].i = level;
  1054.       n[3].i = xoffset;
  1055.       n[4].i = yoffset;
  1056.       n[5].i = zoffset;
  1057.       n[6].i = x;
  1058.       n[7].i = y;
  1059.       n[8].i = width;
  1060.       n[9].i = height;
  1061.    }
  1062.    if (ctx->ExecuteFlag) {
  1063.       EXEC(CopyTexSubImage3DEXT)( ctx, target, level, xoffset, yoffset, zoffset,
  1064.                                x, y, width, height );
  1065.    }
  1066. }
  1067.  
  1068.  
  1069. void gl_save_CullFace( GLcontext *ctx, GLenum mode )
  1070. {
  1071.    Node *n = alloc_instruction( ctx, OPCODE_CULL_FACE, 1 );
  1072.    if (n) {
  1073.       n[1].e = mode;
  1074.    }
  1075.    if (ctx->ExecuteFlag) {
  1076.       EXEC(CullFace)( ctx, mode );
  1077.    }
  1078. }
  1079.  
  1080.  
  1081. void gl_save_DepthFunc( GLcontext *ctx, GLenum func )
  1082. {
  1083.    Node *n = alloc_instruction( ctx, OPCODE_DEPTH_FUNC, 1 );
  1084.    if (n) {
  1085.       n[1].e = func;
  1086.    }
  1087.    if (ctx->ExecuteFlag) {
  1088.       EXEC(DepthFunc)( ctx, func );
  1089.    }
  1090. }
  1091.  
  1092.  
  1093. void gl_save_DepthMask( GLcontext *ctx, GLboolean mask )
  1094. {
  1095.    Node *n = alloc_instruction( ctx, OPCODE_DEPTH_MASK, 1 );
  1096.    if (n) {
  1097.       n[1].b = mask;
  1098.    }
  1099.    if (ctx->ExecuteFlag) {
  1100.       EXEC(DepthMask)( ctx, mask );
  1101.    }
  1102. }
  1103.  
  1104.  
  1105. void gl_save_DepthRange( GLcontext *ctx, GLclampd nearval, GLclampd farval )
  1106. {
  1107.    Node *n = alloc_instruction( ctx, OPCODE_DEPTH_RANGE, 2 );
  1108.    if (n) {
  1109.       n[1].f = (GLfloat) nearval;
  1110.       n[2].f = (GLfloat) farval;
  1111.    }
  1112.    if (ctx->ExecuteFlag) {
  1113.       EXEC(DepthRange)( ctx, nearval, farval );
  1114.    }
  1115. }
  1116.  
  1117.  
  1118. void gl_save_Disable( GLcontext *ctx, GLenum cap )
  1119. {
  1120.    Node *n = alloc_instruction( ctx, OPCODE_DISABLE, 1 );
  1121.    if (n) {
  1122.       n[1].e = cap;
  1123.    }
  1124.    if (ctx->ExecuteFlag) {
  1125.       EXEC(Disable)( ctx, cap );
  1126.    }
  1127. }
  1128.  
  1129.  
  1130. void gl_save_DrawBuffer( GLcontext *ctx, GLenum mode )
  1131. {
  1132.    Node *n = alloc_instruction( ctx, OPCODE_DRAW_BUFFER, 1 );
  1133.    if (n) {
  1134.       n[1].e = mode;
  1135.    }
  1136.    if (ctx->ExecuteFlag) {
  1137.       EXEC(DrawBuffer)( ctx, mode );
  1138.    }
  1139. }
  1140.  
  1141.  
  1142. void gl_save_DrawPixels( GLcontext *ctx, GLsizei width, GLsizei height,
  1143.                          GLenum format, GLenum type, const GLvoid *pixels )
  1144. {
  1145.    Node *n = alloc_instruction( ctx, OPCODE_DRAW_PIXELS, 5 );
  1146.    if (n) {
  1147.       n[1].i = (GLint) width;
  1148.       n[2].i = (GLint) height;
  1149.       n[3].e = format;
  1150.       n[4].e = type;
  1151.       n[5].data = (GLvoid *) pixels;
  1152.    }
  1153.    if (ctx->ExecuteFlag) {
  1154.       EXEC(DrawPixels)( ctx, width, height, format, type, pixels );
  1155.    }
  1156. }
  1157.  
  1158.  
  1159. void gl_save_EdgeFlag( GLcontext *ctx, GLboolean flag )
  1160. {
  1161.    Node *n = alloc_instruction( ctx, OPCODE_EDGE_FLAG, 1 );
  1162.    if (n) {
  1163.       n[1].b = flag;
  1164.    }
  1165.    if (ctx->ExecuteFlag) {
  1166.       EXEC(EdgeFlag)( ctx, flag );
  1167.    }
  1168. }
  1169.  
  1170.  
  1171. void gl_save_Enable( GLcontext *ctx, GLenum cap )
  1172. {
  1173.    Node *n = alloc_instruction( ctx, OPCODE_ENABLE, 1 );
  1174.    if (n) {
  1175.       n[1].e = cap;
  1176.    }
  1177.    if (ctx->ExecuteFlag) {
  1178.       EXEC(Enable)( ctx, cap );
  1179.    }
  1180. }
  1181.  
  1182.  
  1183. void gl_save_End( GLcontext *ctx )
  1184. {
  1185.    (void) alloc_instruction( ctx, OPCODE_END, 0 );
  1186.    if (ctx->ExecuteFlag) {
  1187.       EXEC(End)( ctx );
  1188.    }
  1189. }
  1190.  
  1191.  
  1192. void gl_save_EvalCoord1f( GLcontext *ctx, GLfloat u )
  1193. {
  1194.    Node *n = alloc_instruction( ctx, OPCODE_EVALCOORD1, 1 );
  1195.    if (n) {
  1196.       n[1].f = u;
  1197.    }
  1198.    if (ctx->ExecuteFlag) {
  1199.       EXEC(EvalCoord1f)( ctx, u );
  1200.    }
  1201. }
  1202.  
  1203.  
  1204. void gl_save_EvalCoord2f( GLcontext *ctx, GLfloat u, GLfloat v )
  1205. {
  1206.    Node *n = alloc_instruction( ctx, OPCODE_EVALCOORD2, 2 );
  1207.    if (n) {
  1208.       n[1].f = u;
  1209.       n[2].f = v;
  1210.    }
  1211.    if (ctx->ExecuteFlag) {
  1212.       EXEC(EvalCoord2f)( ctx, u, v );
  1213.    }
  1214. }
  1215.  
  1216.  
  1217. void gl_save_EvalMesh1( GLcontext *ctx,
  1218.                         GLenum mode, GLint i1, GLint i2 )
  1219. {
  1220.    Node *n = alloc_instruction( ctx, OPCODE_EVALMESH1, 3 );
  1221.    if (n) {
  1222.       n[1].e = mode;
  1223.       n[2].i = i1;
  1224.       n[3].i = i2;
  1225.    }
  1226.    if (ctx->ExecuteFlag) {
  1227.       EXEC(EvalMesh1)( ctx, mode, i1, i2 );
  1228.    }
  1229. }
  1230.  
  1231.  
  1232. void gl_save_EvalMesh2( GLcontext *ctx, 
  1233.                         GLenum mode, GLint i1, GLint i2, GLint j1, GLint j2 )
  1234. {
  1235.    Node *n = alloc_instruction( ctx, OPCODE_EVALMESH2, 5 );
  1236.    if (n) {
  1237.       n[1].e = mode;
  1238.       n[2].i = i1;
  1239.       n[3].i = i2;
  1240.       n[4].i = j1;
  1241.       n[5].i = j2;
  1242.    }
  1243.    if (ctx->ExecuteFlag) {
  1244.       EXEC(EvalMesh2)( ctx, mode, i1, i2, j1, j2 );
  1245.    }
  1246. }
  1247.  
  1248.  
  1249. void gl_save_EvalPoint1( GLcontext *ctx, GLint i )
  1250. {
  1251.    Node *n = alloc_instruction( ctx, OPCODE_EVALPOINT1, 1 );
  1252.    if (n) {
  1253.       n[1].i = i;
  1254.    }
  1255.    if (ctx->ExecuteFlag) {
  1256.       EXEC(EvalPoint1)( ctx, i );
  1257.    }
  1258. }
  1259.  
  1260.  
  1261. void gl_save_EvalPoint2( GLcontext *ctx, GLint i, GLint j )
  1262. {
  1263.    Node *n = alloc_instruction( ctx, OPCODE_EVALPOINT2, 2 );
  1264.    if (n) {
  1265.       n[1].i = i;
  1266.       n[2].i = j;
  1267.    }
  1268.    if (ctx->ExecuteFlag) {
  1269.       EXEC(EvalPoint2)( ctx, i, j );
  1270.    }
  1271. }
  1272.  
  1273.  
  1274. void gl_save_Fogfv( GLcontext *ctx, GLenum pname, const GLfloat *params )
  1275. {
  1276.    Node *n = alloc_instruction( ctx, OPCODE_FOG, 5 );
  1277.    if (n) {
  1278.       n[1].e = pname;
  1279.       n[2].f = params[0];
  1280.       n[3].f = params[1];
  1281.       n[4].f = params[2];
  1282.       n[5].f = params[3];
  1283.    }
  1284.    if (ctx->ExecuteFlag) {
  1285.       EXEC(Fogfv)( ctx, pname, params );
  1286.    }
  1287. }
  1288.  
  1289.  
  1290. void gl_save_FrontFace( GLcontext *ctx, GLenum mode )
  1291. {
  1292.    Node *n = alloc_instruction( ctx, OPCODE_FRONT_FACE, 1 );
  1293.    if (n) {
  1294.       n[1].e = mode;
  1295.    }
  1296.    if (ctx->ExecuteFlag) {
  1297.       EXEC(FrontFace)( ctx, mode );
  1298.    }
  1299. }
  1300.  
  1301.  
  1302. void gl_save_Frustum( GLcontext *ctx, GLdouble left, GLdouble right,
  1303.                       GLdouble bottom, GLdouble top,
  1304.                       GLdouble nearval, GLdouble farval )
  1305. {
  1306.    Node *n = alloc_instruction( ctx, OPCODE_FRUSTUM, 6 );
  1307.    if (n) {
  1308.       n[1].f = left;
  1309.       n[2].f = right;
  1310.       n[3].f = bottom;
  1311.       n[4].f = top;
  1312.       n[5].f = nearval;
  1313.       n[6].f = farval;
  1314.    }
  1315.    if (ctx->ExecuteFlag) {
  1316.       EXEC(Frustum)( ctx, left, right, bottom, top, nearval, farval );
  1317.    }
  1318. }
  1319.  
  1320.  
  1321. void gl_save_Hint( GLcontext *ctx, GLenum target, GLenum mode )
  1322. {
  1323.    Node *n = alloc_instruction( ctx, OPCODE_HINT, 2 );
  1324.    if (n) {
  1325.       n[1].e = target;
  1326.       n[2].e = mode;
  1327.    }
  1328.    if (ctx->ExecuteFlag) {
  1329.       EXEC(Hint)( ctx, target, mode );
  1330.    }
  1331. }
  1332.  
  1333.  
  1334. void gl_save_Indexi( GLcontext *ctx, GLint index )
  1335. {
  1336.    Node *n = alloc_instruction( ctx, OPCODE_INDEX, 1 );
  1337.    if (n) {
  1338.       n[1].i = index;
  1339.    }
  1340.    if (ctx->ExecuteFlag) {
  1341.       EXEC(Indexi)( ctx, index );
  1342.    }
  1343. }
  1344.  
  1345.  
  1346. void gl_save_Indexf( GLcontext *ctx, GLfloat index )
  1347. {
  1348.    Node *n = alloc_instruction( ctx, OPCODE_INDEX, 1 );
  1349.    if (n) {
  1350.       n[1].i = (GLint) index;
  1351.    }
  1352.    if (ctx->ExecuteFlag) {
  1353.       EXEC(Indexf)( ctx,index );
  1354.    }
  1355. }
  1356.  
  1357.  
  1358. void gl_save_IndexMask( GLcontext *ctx, GLuint mask )
  1359. {
  1360.    Node *n = alloc_instruction( ctx, OPCODE_INDEX_MASK, 1 );
  1361.    if (n) {
  1362.       n[1].ui = mask;
  1363.    }
  1364.    if (ctx->ExecuteFlag) {
  1365.       EXEC(IndexMask)( ctx, mask );
  1366.    }
  1367. }
  1368.  
  1369.  
  1370. void gl_save_InitNames( GLcontext *ctx )
  1371. {
  1372.    (void) alloc_instruction( ctx, OPCODE_INIT_NAMES, 0 );
  1373.    if (ctx->ExecuteFlag) {
  1374.       EXEC(InitNames)( ctx );
  1375.    }
  1376. }
  1377.  
  1378.  
  1379. void gl_save_Lightfv( GLcontext *ctx, GLenum light, GLenum pname,
  1380.                       const GLfloat *params, GLint numparams )
  1381. {
  1382.    Node *n = alloc_instruction( ctx, OPCODE_LIGHT, 6 );
  1383.    if (OPCODE_LIGHT) {
  1384.       GLint i;
  1385.       n[1].e = light;
  1386.       n[2].e = pname;
  1387.       for (i=0;i<numparams;i++) {
  1388.      n[3+i].f = params[i];
  1389.       }
  1390.    }
  1391.    if (ctx->ExecuteFlag) {
  1392.       EXEC(Lightfv)( ctx, light, pname, params, numparams );
  1393.    }
  1394. }
  1395.  
  1396.  
  1397. void gl_save_LightModelfv( GLcontext *ctx,
  1398.                            GLenum pname, const GLfloat *params )
  1399. {
  1400.    Node *n = alloc_instruction( ctx, OPCODE_LIGHT_MODEL, 5 );
  1401.    if (n) {
  1402.       n[1].e = pname;
  1403.       n[2].f = params[0];
  1404.       n[3].f = params[1];
  1405.       n[4].f = params[2];
  1406.       n[5].f = params[3];
  1407.    }
  1408.    if (ctx->ExecuteFlag) {
  1409.       EXEC(LightModelfv)( ctx, pname, params );
  1410.    }
  1411. }
  1412.  
  1413.  
  1414. void gl_save_LineStipple( GLcontext *ctx, GLint factor, GLushort pattern )
  1415. {
  1416.    Node *n = alloc_instruction( ctx, OPCODE_LINE_STIPPLE, 2 );
  1417.    if (n) {
  1418.       n[1].i = factor;
  1419.       n[2].us = pattern;
  1420.    }
  1421.    if (ctx->ExecuteFlag) {
  1422.       EXEC(LineStipple)( ctx, factor, pattern );
  1423.    }
  1424. }
  1425.  
  1426.  
  1427. void gl_save_LineWidth( GLcontext *ctx, GLfloat width )
  1428. {
  1429.    Node *n = alloc_instruction( ctx, OPCODE_LINE_WIDTH, 1 );
  1430.    if (n) {
  1431.       n[1].f = width;
  1432.    }
  1433.    if (ctx->ExecuteFlag) {
  1434.       EXEC(LineWidth)( ctx, width );
  1435.    }
  1436. }
  1437.  
  1438.  
  1439. void gl_save_ListBase( GLcontext *ctx, GLuint base )
  1440. {
  1441.    Node *n = alloc_instruction( ctx, OPCODE_LIST_BASE, 1 );
  1442.    if (n) {
  1443.       n[1].ui = base;
  1444.    }
  1445.    if (ctx->ExecuteFlag) {
  1446.       EXEC(ListBase)( ctx, base );
  1447.    }
  1448. }
  1449.  
  1450.  
  1451. void gl_save_LoadMatrixf( GLcontext *ctx, const GLfloat *m )
  1452. {
  1453.    Node *n = alloc_instruction( ctx, OPCODE_LOAD_MATRIX, 16 );
  1454.    if (n) {
  1455.       GLuint i;
  1456.       for (i=0;i<16;i++) {
  1457.      n[1+i].f = m[i];
  1458.       }
  1459.    }
  1460.    if (ctx->ExecuteFlag) {
  1461.       EXEC(LoadMatrixf)( ctx, m );
  1462.    }
  1463. }
  1464.  
  1465.  
  1466. void gl_save_LoadName( GLcontext *ctx, GLuint name )
  1467. {
  1468.    Node *n = alloc_instruction( ctx, OPCODE_LOAD_NAME, 1 );
  1469.    if (n) {
  1470.       n[1].ui = name;
  1471.    }
  1472.    if (ctx->ExecuteFlag) {
  1473.       EXEC(LoadName)( ctx, name );
  1474.    }
  1475. }
  1476.  
  1477.  
  1478. void gl_save_LogicOp( GLcontext *ctx, GLenum opcode )
  1479. {
  1480.    Node *n = alloc_instruction( ctx, OPCODE_LOGIC_OP, 1 );
  1481.    if (n) {
  1482.       n[1].e = opcode;
  1483.    }
  1484.    if (ctx->ExecuteFlag) {
  1485.       EXEC(LogicOp)( ctx, opcode );
  1486.    }
  1487. }
  1488.  
  1489.  
  1490. void gl_save_Map1f( GLcontext *ctx,
  1491.                    GLenum target, GLfloat u1, GLfloat u2, GLint stride,
  1492.            GLint order, const GLfloat *points, GLboolean retain )
  1493. {
  1494.    Node *n = alloc_instruction( ctx, OPCODE_MAP1, 6 );
  1495.    if (n) {
  1496.       n[1].e = target;
  1497.       n[2].f = u1;
  1498.       n[3].f = u2;
  1499.       n[4].i = stride;
  1500.       n[5].i = order;
  1501.       n[6].data = (void *) points;
  1502.    }
  1503.    if (ctx->ExecuteFlag) {
  1504.       EXEC(Map1f)( ctx, target, u1, u2, stride, order, points, GL_TRUE );
  1505.    }
  1506. }
  1507.  
  1508.  
  1509. void gl_save_Map2f( GLcontext *ctx, GLenum target,
  1510.                     GLfloat u1, GLfloat u2, GLint ustride, GLint uorder,
  1511.                     GLfloat v1, GLfloat v2, GLint vstride, GLint vorder,
  1512.                     const GLfloat *points, GLboolean retain )
  1513. {
  1514.    Node *n = alloc_instruction( ctx, OPCODE_MAP2, 10 );
  1515.    if (n) {
  1516.       n[1].e = target;
  1517.       n[2].f = u1;
  1518.       n[3].f = u2;
  1519.       n[4].f = v1;
  1520.       n[5].f = v2;
  1521.       n[6].i = ustride;
  1522.       n[7].i = vstride;
  1523.       n[8].i = uorder;
  1524.       n[9].i = vorder;
  1525.       n[10].data = (void *) points;
  1526.    }
  1527.    if (ctx->ExecuteFlag) {
  1528.       EXEC(Map2f)( ctx, target,
  1529.                         u1, u2, ustride, uorder,
  1530.                         v1, v2, vstride, vorder, points, GL_TRUE );
  1531.    }
  1532. }
  1533.  
  1534.  
  1535. void gl_save_MapGrid1f( GLcontext *ctx, GLint un, GLfloat u1, GLfloat u2 )
  1536. {
  1537.    Node *n = alloc_instruction( ctx, OPCODE_MAPGRID1, 3 );
  1538.    if (n) {
  1539.       n[1].i = un;
  1540.       n[2].f = u1;
  1541.       n[3].f = u2;
  1542.    }
  1543.    if (ctx->ExecuteFlag) {
  1544.       EXEC(MapGrid1f)( ctx, un, u1, u2 );
  1545.    }
  1546. }
  1547.  
  1548.  
  1549. void gl_save_MapGrid2f( GLcontext *ctx, 
  1550.                         GLint un, GLfloat u1, GLfloat u2,
  1551.                 GLint vn, GLfloat v1, GLfloat v2 )
  1552. {
  1553.    Node *n = alloc_instruction( ctx, OPCODE_MAPGRID2, 6 );
  1554.    if (n) {
  1555.       n[1].i = un;
  1556.       n[2].f = u1;
  1557.       n[3].f = u2;
  1558.       n[4].i = vn;
  1559.       n[5].f = v1;
  1560.       n[6].f = v2;
  1561.    }
  1562.    if (ctx->ExecuteFlag) {
  1563.       EXEC(MapGrid2f)( ctx, un, u1, u2, vn, v1, v2 );
  1564.    }
  1565. }
  1566.  
  1567.  
  1568. void gl_save_Materialfv( GLcontext *ctx,
  1569.                          GLenum face, GLenum pname, const GLfloat *params )
  1570. {
  1571.    Node *n = alloc_instruction( ctx, OPCODE_MATERIAL, 6 );
  1572.    if (n) {
  1573.       n[1].e = face;
  1574.       n[2].e = pname;
  1575.       n[3].f = params[0];
  1576.       n[4].f = params[1];
  1577.       n[5].f = params[2];
  1578.       n[6].f = params[3];
  1579.    }
  1580.    if (ctx->ExecuteFlag) {
  1581.       EXEC(Materialfv)( ctx, face, pname, params );
  1582.    }
  1583. }
  1584.  
  1585.  
  1586. void gl_save_MatrixMode( GLcontext *ctx, GLenum mode )
  1587. {
  1588.    Node *n = alloc_instruction( ctx, OPCODE_MATRIX_MODE, 1 );
  1589.    if (n) {
  1590.       n[1].e = mode;
  1591.    }
  1592.    if (ctx->ExecuteFlag) {
  1593.       EXEC(MatrixMode)( ctx, mode );
  1594.    }
  1595. }
  1596.  
  1597.  
  1598. void gl_save_MultMatrixf( GLcontext *ctx, const GLfloat *m )
  1599. {
  1600.    Node *n = alloc_instruction( ctx, OPCODE_MULT_MATRIX, 16 );
  1601.    if (n) {
  1602.       GLuint i;
  1603.       for (i=0;i<16;i++) {
  1604.      n[1+i].f = m[i];
  1605.       }
  1606.    }
  1607.    if (ctx->ExecuteFlag) {
  1608.       EXEC(MultMatrixf)( ctx, m );
  1609.    }
  1610. }
  1611.  
  1612.  
  1613. void gl_save_NewList( GLcontext *ctx, GLuint list, GLenum mode )
  1614. {
  1615.    /* It's an error to call this function while building a display list */
  1616.    gl_error( ctx, GL_INVALID_OPERATION, "glNewList" );
  1617. }
  1618.  
  1619.  
  1620. void gl_save_Normal3fv( GLcontext *ctx, const GLfloat norm[3] )
  1621. {
  1622.    Node *n = alloc_instruction( ctx, OPCODE_NORMAL, 3 );
  1623.    if (n) {
  1624.       n[1].f = norm[0];
  1625.       n[2].f = norm[1];
  1626.       n[3].f = norm[2];
  1627.    }
  1628.    if (ctx->ExecuteFlag) {
  1629.       EXEC(Normal3fv)( ctx, norm );
  1630.    }
  1631. }
  1632.  
  1633.  
  1634. void gl_save_Normal3f( GLcontext *ctx, GLfloat nx, GLfloat ny, GLfloat nz )
  1635. {
  1636.    Node *n = alloc_instruction( ctx, OPCODE_NORMAL, 3 );
  1637.    if (n) {
  1638.       n[1].f = nx;
  1639.       n[2].f = ny;
  1640.       n[3].f = nz;
  1641.    }
  1642.    if (ctx->ExecuteFlag) {
  1643.       EXEC(Normal3f)( ctx, nx, ny, nz );
  1644.    }
  1645. }
  1646.  
  1647.  
  1648. void gl_save_PixelMapfv( GLcontext *ctx,
  1649.                          GLenum map, GLint mapsize, const GLfloat *values )
  1650. {
  1651.    Node *n = alloc_instruction( ctx, OPCODE_PIXEL_MAP, 3 );
  1652.    if (n) {
  1653.       n[1].e = map;
  1654.       n[2].i = mapsize;
  1655.       n[3].data  = (void *) malloc( mapsize * sizeof(GLfloat) );
  1656.       MEMCPY( n[3].data, (void *) values, mapsize * sizeof(GLfloat) );
  1657.    }
  1658.    if (ctx->ExecuteFlag) {
  1659.       EXEC(PixelMapfv)( ctx, map, mapsize, values );
  1660.    }
  1661. }
  1662.  
  1663.  
  1664. void gl_save_PixelTransferf( GLcontext *ctx, GLenum pname, GLfloat param )
  1665. {
  1666.    Node *n = alloc_instruction( ctx, OPCODE_PIXEL_TRANSFER, 2 );
  1667.    if (n) {
  1668.       n[1].e = pname;
  1669.       n[2].f = param;
  1670.    }
  1671.    if (ctx->ExecuteFlag) {
  1672.       EXEC(PixelTransferf)( ctx, pname, param );
  1673.    }
  1674. }
  1675.  
  1676.  
  1677. void gl_save_PixelZoom( GLcontext *ctx, GLfloat xfactor, GLfloat yfactor )
  1678. {
  1679.    Node *n = alloc_instruction( ctx, OPCODE_PIXEL_ZOOM, 2 );
  1680.    if (n) {
  1681.       n[1].f = xfactor;
  1682.       n[2].f = yfactor;
  1683.    }
  1684.    if (ctx->ExecuteFlag) {
  1685.       EXEC(PixelZoom)( ctx, xfactor, yfactor );
  1686.    }
  1687. }
  1688.  
  1689.  
  1690. void gl_save_PointSize( GLcontext *ctx, GLfloat size )
  1691. {
  1692.    Node *n = alloc_instruction( ctx, OPCODE_POINTSIZE, 1 );
  1693.    if (n) {
  1694.       n[1].f = size;
  1695.    }
  1696.    if (ctx->ExecuteFlag) {
  1697.       EXEC(PointSize)( ctx, size );
  1698.    }
  1699. }
  1700.  
  1701.  
  1702. void gl_save_PolygonMode( GLcontext *ctx, GLenum face, GLenum mode )
  1703. {
  1704.    Node *n = alloc_instruction( ctx, OPCODE_POLYGON_MODE, 2 );
  1705.    if (n) {
  1706.       n[1].e = face;
  1707.       n[2].e = mode;
  1708.    }
  1709.    if (ctx->ExecuteFlag) {
  1710.       EXEC(PolygonMode)( ctx, face, mode );
  1711.    }
  1712. }
  1713.  
  1714.  
  1715. void gl_save_PolygonStipple( GLcontext *ctx, const GLubyte *mask )
  1716. {
  1717.    Node *n = alloc_instruction( ctx, OPCODE_POLYGON_STIPPLE, 1 );
  1718.    if (n) {
  1719.       void *data;
  1720.       n[1].data = malloc( 32 * 4 );
  1721.       data = n[1].data;   /* This needed for Acorn compiler */
  1722.       MEMCPY( data, mask, 32 * 4 );
  1723.    }
  1724.    if (ctx->ExecuteFlag) {
  1725.       EXEC(PolygonStipple)( ctx, mask );
  1726.    }
  1727. }
  1728.  
  1729.  
  1730. void gl_save_PolygonOffset( GLcontext *ctx, GLfloat factor, GLfloat units )
  1731. {
  1732.    Node *n = alloc_instruction( ctx, OPCODE_POLYGON_OFFSET, 2 );
  1733.    if (n) {
  1734.       n[1].f = factor;
  1735.       n[2].f = units;
  1736.    }
  1737.    if (ctx->ExecuteFlag) {
  1738.       EXEC(PolygonOffset)( ctx, factor, units );
  1739.    }
  1740. }
  1741.  
  1742.  
  1743. void gl_save_PopAttrib( GLcontext *ctx )
  1744. {
  1745.    (void) alloc_instruction( ctx, OPCODE_POP_ATTRIB, 0 );
  1746.    if (ctx->ExecuteFlag) {
  1747.       EXEC(PopAttrib)( ctx );
  1748.    }
  1749. }
  1750.  
  1751.  
  1752. void gl_save_PopMatrix( GLcontext *ctx )
  1753. {
  1754.    (void) alloc_instruction( ctx, OPCODE_POP_MATRIX, 0 );
  1755.    if (ctx->ExecuteFlag) {
  1756.       EXEC(PopMatrix)( ctx );
  1757.    }
  1758. }
  1759.  
  1760.  
  1761. void gl_save_PopName( GLcontext *ctx )
  1762. {
  1763.    (void) alloc_instruction( ctx, OPCODE_POP_NAME, 0 );
  1764.    if (ctx->ExecuteFlag) {
  1765.       EXEC(PopName)( ctx );
  1766.    }
  1767. }
  1768.  
  1769.  
  1770. void gl_save_PrioritizeTextures( GLcontext *ctx,
  1771.                                  GLsizei num, const GLuint *textures,
  1772.                                  const GLclampf *priorities )
  1773. {
  1774.    GLint i;
  1775.  
  1776.    for (i=0;i<num;i++) {
  1777.       Node *n = alloc_instruction( ctx,  OPCODE_PRIORITIZE_TEXTURE, 2 );
  1778.       if (n) {
  1779.          n[1].ui = textures[i];
  1780.          n[2].f = priorities[i];
  1781.       }
  1782.    }
  1783.    if (ctx->ExecuteFlag) {
  1784.       EXEC(PrioritizeTextures)( ctx, num, textures, priorities );
  1785.    }
  1786. }
  1787.  
  1788.  
  1789. void gl_save_PushAttrib( GLcontext *ctx, GLbitfield mask )
  1790. {
  1791.    Node *n = alloc_instruction( ctx, OPCODE_PUSH_ATTRIB, 1 );
  1792.    if (n) {
  1793.       n[1].bf = mask;
  1794.    }
  1795.    if (ctx->ExecuteFlag) {
  1796.       EXEC(PushAttrib)( ctx, mask );
  1797.    }
  1798. }
  1799.  
  1800.  
  1801. void gl_save_PushMatrix( GLcontext *ctx )
  1802. {
  1803.    (void) alloc_instruction( ctx, OPCODE_PUSH_MATRIX, 0 );
  1804.    if (ctx->ExecuteFlag) {
  1805.       EXEC(PushMatrix)( ctx );
  1806.    }
  1807. }
  1808.  
  1809.  
  1810. void gl_save_PushName( GLcontext *ctx, GLuint name )
  1811. {
  1812.    Node *n = alloc_instruction( ctx, OPCODE_PUSH_NAME, 1 );
  1813.    if (n) {
  1814.       n[1].ui = name;
  1815.    }
  1816.    if (ctx->ExecuteFlag) {
  1817.       EXEC(PushName)( ctx, name );
  1818.    }
  1819. }
  1820.  
  1821.  
  1822. void gl_save_RasterPos4f( GLcontext *ctx,
  1823.                           GLfloat x, GLfloat y, GLfloat z, GLfloat w )
  1824. {
  1825.    Node *n = alloc_instruction( ctx, OPCODE_RASTER_POS, 4 );
  1826.    if (n) {
  1827.       n[1].f = x;
  1828.       n[2].f = y;
  1829.       n[3].f = z;
  1830.       n[4].f = w;
  1831.    }
  1832.    if (ctx->ExecuteFlag) {
  1833.       EXEC(RasterPos4f)( ctx, x, y, z, w );
  1834.    }
  1835. }
  1836.  
  1837.  
  1838. void gl_save_PassThrough( GLcontext *ctx, GLfloat token )
  1839. {
  1840.    Node *n = alloc_instruction( ctx, OPCODE_PASSTHROUGH, 1 );
  1841.    if (n) {
  1842.       n[1].f = token;
  1843.    }
  1844.    if (ctx->ExecuteFlag) {
  1845.       EXEC(PassThrough)( ctx, token );
  1846.    }
  1847. }
  1848.  
  1849.  
  1850. void gl_save_ReadBuffer( GLcontext *ctx, GLenum mode )
  1851. {
  1852.    Node *n = alloc_instruction( ctx, OPCODE_READ_BUFFER, 1 );
  1853.    if (n) {
  1854.       n[1].e = mode;
  1855.    }
  1856.    if (ctx->ExecuteFlag) {
  1857.       EXEC(ReadBuffer)( ctx, mode );
  1858.    }
  1859. }
  1860.  
  1861.  
  1862. void gl_save_Rotatef( GLcontext *ctx, GLfloat angle,
  1863.                       GLfloat x, GLfloat y, GLfloat z )
  1864. {
  1865.    GLfloat m[16];
  1866.    gl_rotation_matrix( angle, x, y, z, m );
  1867.    gl_save_MultMatrixf( ctx, m );  /* save and maybe execute */
  1868. }
  1869.  
  1870.  
  1871. void gl_save_Scalef( GLcontext *ctx, GLfloat x, GLfloat y, GLfloat z )
  1872. {
  1873.    Node *n = alloc_instruction( ctx, OPCODE_SCALE, 3 );
  1874.    if (n) {
  1875.       n[1].f = x;
  1876.       n[2].f = y;
  1877.       n[3].f = z;
  1878.    }
  1879.    if (ctx->ExecuteFlag) {
  1880.       EXEC(Scalef)( ctx, x, y, z );
  1881.    }
  1882. }
  1883.  
  1884.  
  1885. void gl_save_Scissor( GLcontext *ctx,
  1886.                       GLint x, GLint y, GLsizei width, GLsizei height )
  1887. {
  1888.    Node *n = alloc_instruction( ctx, OPCODE_SCISSOR, 4 );
  1889.    if (n) {
  1890.       n[1].i = x;
  1891.       n[2].i = y;
  1892.       n[3].i = width;
  1893.       n[4].i = height;
  1894.    }
  1895.    if (ctx->ExecuteFlag) {
  1896.       EXEC(Scissor)( ctx, x, y, width, height );
  1897.    }
  1898. }
  1899.  
  1900.  
  1901. void gl_save_ShadeModel( GLcontext *ctx, GLenum mode )
  1902. {
  1903.    Node *n = alloc_instruction( ctx, OPCODE_SHADE_MODEL, 1 );
  1904.    if (n) {
  1905.       n[1].e = mode;
  1906.    }
  1907.    if (ctx->ExecuteFlag) {
  1908.       EXEC(ShadeModel)( ctx, mode );
  1909.    }
  1910. }
  1911.  
  1912.  
  1913. void gl_save_StencilFunc( GLcontext *ctx, GLenum func, GLint ref, GLuint mask )
  1914. {
  1915.    Node *n = alloc_instruction( ctx, OPCODE_STENCIL_FUNC, 3 );
  1916.    if (n) {
  1917.       n[1].e = func;
  1918.       n[2].i = ref;
  1919.       n[3].ui = mask;
  1920.    }
  1921.    if (ctx->ExecuteFlag) {
  1922.       EXEC(StencilFunc)( ctx, func, ref, mask );
  1923.    }
  1924. }
  1925.  
  1926.  
  1927. void gl_save_StencilMask( GLcontext *ctx, GLuint mask )
  1928. {
  1929.    Node *n = alloc_instruction( ctx, OPCODE_STENCIL_MASK, 1 );
  1930.    if (n) {
  1931.       n[1].ui = mask;
  1932.    }
  1933.    if (ctx->ExecuteFlag) {
  1934.       EXEC(StencilMask)( ctx, mask );
  1935.    }
  1936. }
  1937.  
  1938.  
  1939. void gl_save_StencilOp( GLcontext *ctx,
  1940.                         GLenum fail, GLenum zfail, GLenum zpass )
  1941. {
  1942.    Node *n = alloc_instruction( ctx, OPCODE_STENCIL_OP, 3 );
  1943.    if (n) {
  1944.       n[1].e = fail;
  1945.       n[2].e = zfail;
  1946.       n[3].e = zpass;
  1947.    }
  1948.    if (ctx->ExecuteFlag) {
  1949.       EXEC(StencilOp)( ctx, fail, zfail, zpass );
  1950.    }
  1951. }
  1952.  
  1953.  
  1954. void gl_save_TexCoord4f( GLcontext *ctx, GLfloat s, GLfloat t,
  1955.                                          GLfloat r, GLfloat q )
  1956. {
  1957.    Node *n = alloc_instruction( ctx, OPCODE_TEXCOORD, 4 );
  1958.    if (n) {
  1959.       n[1].f = s;
  1960.       n[2].f = t;
  1961.       n[3].f = r;
  1962.       n[4].f = q;
  1963.    }
  1964.    if (ctx->ExecuteFlag) {
  1965.       EXEC(TexCoord4f)( ctx, s, t, r, q );
  1966.    }
  1967. }
  1968.  
  1969.  
  1970. void gl_save_TexEnvfv( GLcontext *ctx,
  1971.                        GLenum target, GLenum pname, const GLfloat *params )
  1972. {
  1973.    Node *n = alloc_instruction( ctx, OPCODE_TEXENV, 6 );
  1974.    if (n) {
  1975.       n[1].e = target;
  1976.       n[2].e = pname;
  1977.       n[3].f = params[0];
  1978.       n[4].f = params[1];
  1979.       n[5].f = params[2];
  1980.       n[6].f = params[3];
  1981.    }
  1982.    if (ctx->ExecuteFlag) {
  1983.       EXEC(TexEnvfv)( ctx, target, pname, params );
  1984.    }
  1985. }
  1986.  
  1987.  
  1988. void gl_save_TexGenfv( GLcontext *ctx,
  1989.                        GLenum coord, GLenum pname, const GLfloat *params )
  1990. {
  1991.    Node *n = alloc_instruction( ctx, OPCODE_TEXGEN, 6 );
  1992.    if (n) {
  1993.       n[1].e = coord;
  1994.       n[2].e = pname;
  1995.       n[3].f = params[0];
  1996.       n[4].f = params[1];
  1997.       n[5].f = params[2];
  1998.       n[6].f = params[3];
  1999.    }
  2000.    if (ctx->ExecuteFlag) {
  2001.       EXEC(TexGenfv)( ctx, coord, pname, params );
  2002.    }
  2003. }
  2004.  
  2005.  
  2006. void gl_save_TexParameterfv( GLcontext *ctx, GLenum target,
  2007.                              GLenum pname, const GLfloat *params )
  2008. {
  2009.    Node *n = alloc_instruction( ctx, OPCODE_TEXPARAMETER, 6 );
  2010.    if (n) {
  2011.       n[1].e = target;
  2012.       n[2].e = pname;
  2013.       n[3].f = params[0];
  2014.       n[4].f = params[1];
  2015.       n[5].f = params[2];
  2016.       n[6].f = params[3];
  2017.    }
  2018.    if (ctx->ExecuteFlag) {
  2019.       EXEC(TexParameterfv)( ctx, target, pname, params );
  2020.    }
  2021. }
  2022.  
  2023.  
  2024. void gl_save_TexImage1D( GLcontext *ctx, GLenum target,
  2025.                          GLint level, GLint components,
  2026.              GLsizei width, GLint border,
  2027.                          GLenum format, GLenum type,
  2028.              struct gl_image *teximage )
  2029. {
  2030.    Node *n = alloc_instruction( ctx, OPCODE_TEX_IMAGE1D, 8 );
  2031.    if (n) {
  2032.       n[1].e = target;
  2033.       n[2].i = level;
  2034.       n[3].i = components;
  2035.       n[4].i = (GLint) width;
  2036.       n[5].i = border;
  2037.       n[6].e = format;
  2038.       n[7].e = type;
  2039.       n[8].data = teximage;
  2040.       if (teximage) {
  2041.          /* this prevents gl_TexImage2D() from freeing the image */
  2042.          teximage->RefCount = 1;
  2043.       }
  2044.    }
  2045.    if (ctx->ExecuteFlag) {
  2046.       EXEC(TexImage1D)( ctx, target, level, components, width,
  2047.                         border, format, type, teximage );
  2048.    }
  2049. }
  2050.  
  2051.  
  2052. void gl_save_TexImage2D( GLcontext *ctx, GLenum target,
  2053.                          GLint level, GLint components,
  2054.              GLsizei width, GLsizei height, GLint border,
  2055.                          GLenum format, GLenum type,
  2056.              struct gl_image *teximage )
  2057. {
  2058.    Node *n = alloc_instruction( ctx, OPCODE_TEX_IMAGE2D, 9 );
  2059.    if (n) {
  2060.       n[1].e = target;
  2061.       n[2].i = level;
  2062.       n[3].i = components;
  2063.       n[4].i = (GLint) width;
  2064.       n[5].i = (GLint) height;
  2065.       n[6].i = border;
  2066.       n[7].e = format;
  2067.       n[8].e = type;
  2068.       n[9].data = teximage;
  2069.       if (teximage) {
  2070.          /* this prevents gl_TexImage2D() from freeing the image */
  2071.          teximage->RefCount = 1;
  2072.       }
  2073.    }
  2074.    if (ctx->ExecuteFlag) {
  2075.       EXEC(TexImage2D)( ctx, target, level, components, width,
  2076.                         height, border, format, type, teximage );
  2077.    }
  2078. }
  2079.  
  2080.  
  2081. void gl_save_TexImage3DEXT( GLcontext *ctx, GLenum target,
  2082.                             GLint level, GLint components,
  2083.                             GLsizei width, GLsizei height, GLsizei depth,
  2084.                             GLint border,
  2085.                             GLenum format, GLenum type,
  2086.                             struct gl_image *teximage )
  2087. {
  2088.    Node *n = alloc_instruction( ctx, OPCODE_TEX_IMAGE3D, 10 );
  2089.    if (n) {
  2090.       n[1].e = target;
  2091.       n[2].i = level;
  2092.       n[3].i = components;
  2093.       n[4].i = (GLint) width;
  2094.       n[5].i = (GLint) height;
  2095.       n[6].i = (GLint) depth; 
  2096.       n[7].i = border;
  2097.       n[8].e = format;
  2098.       n[9].e = type;
  2099.       n[10].data = teximage;
  2100.    }
  2101.    if (ctx->ExecuteFlag) {
  2102.       EXEC(TexImage3DEXT)( ctx, target, level, components, width,
  2103.                            height, depth, border, format, type, teximage );
  2104.    }
  2105. }
  2106.  
  2107.  
  2108. void gl_save_TexSubImage1D( GLcontext *ctx,
  2109.                             GLenum target, GLint level, GLint xoffset,
  2110.                             GLsizei width, GLenum format, GLenum type,
  2111.                             struct gl_image *image )
  2112. {
  2113.    Node *n = alloc_instruction( ctx, OPCODE_TEX_SUB_IMAGE1D, 7 );
  2114.    if (n) {
  2115.       n[1].e = target;
  2116.       n[2].i = level;
  2117.       n[3].i = xoffset;
  2118.       n[4].i = (GLint) width;
  2119.       n[5].e = format;
  2120.       n[6].e = type;
  2121.       n[7].data = image;
  2122.    }
  2123.    if (ctx->ExecuteFlag) {
  2124.       EXEC(TexSubImage1D)( ctx, target, level, xoffset, width,
  2125.                            format, type, image );
  2126.    }
  2127. }
  2128.  
  2129.  
  2130. void gl_save_TexSubImage2D( GLcontext *ctx,
  2131.                             GLenum target, GLint level,
  2132.                             GLint xoffset, GLint yoffset,
  2133.                             GLsizei width, GLsizei height,
  2134.                             GLenum format, GLenum type,
  2135.                             struct gl_image *image )
  2136. {
  2137.    Node *n = alloc_instruction( ctx, OPCODE_TEX_SUB_IMAGE2D, 9 );
  2138.    if (n) {
  2139.       n[1].e = target;
  2140.       n[2].i = level;
  2141.       n[3].i = xoffset;
  2142.       n[4].i = yoffset;
  2143.       n[5].i = (GLint) width;
  2144.       n[6].i = (GLint) height;
  2145.       n[7].e = format;
  2146.       n[8].e = type;
  2147.       n[9].data = image;
  2148.    }
  2149.    if (ctx->ExecuteFlag) {
  2150.       EXEC(TexSubImage2D)( ctx, target, level, xoffset, yoffset,
  2151.                            width, height, format, type, image );
  2152.    }
  2153. }
  2154.  
  2155.  
  2156. void gl_save_TexSubImage3DEXT( GLcontext *ctx,
  2157.                                GLenum target, GLint level,
  2158.                                GLint xoffset, GLint yoffset,GLint zoffset,
  2159.                                GLsizei width, GLsizei height, GLsizei depth,
  2160.                                GLenum format, GLenum type,
  2161.                                struct gl_image *image )
  2162. {
  2163.    Node *n = alloc_instruction( ctx, OPCODE_TEX_SUB_IMAGE3D, 11 );
  2164.    if (n) {
  2165.       n[1].e = target;
  2166.       n[2].i = level;
  2167.       n[3].i = xoffset;
  2168.       n[4].i = yoffset;
  2169.       n[5].i = zoffset;
  2170.       n[6].i = (GLint) width;
  2171.       n[7].i = (GLint) height;
  2172.       n[8].i = (GLint) depth;
  2173.       n[9].e = format;
  2174.       n[10].e = type;
  2175.       n[11].data = image;
  2176.    }
  2177.    if (ctx->ExecuteFlag) {
  2178.       EXEC(TexSubImage3DEXT)( ctx, target, level, xoffset, yoffset, zoffset,
  2179.                               width, height, depth, format, type, image );
  2180.    }
  2181. }
  2182.  
  2183.  
  2184. void gl_save_Translatef( GLcontext *ctx, GLfloat x, GLfloat y, GLfloat z )
  2185. {
  2186.    Node *n = alloc_instruction( ctx,  OPCODE_TRANSLATE, 3 );
  2187.    if (n) {
  2188.       n[1].f = x;
  2189.       n[2].f = y;
  2190.       n[3].f = z;
  2191.    }
  2192.    if (ctx->ExecuteFlag) {
  2193.       EXEC(Translatef)( ctx, x, y, z );
  2194.    }
  2195. }
  2196.  
  2197.  
  2198. void gl_save_Vertex4f( GLcontext *ctx,
  2199.                        GLfloat x, GLfloat y, GLfloat z, GLfloat w )
  2200. {
  2201.    Node *n = alloc_instruction( ctx,  OPCODE_VERTEX, 4 );
  2202.    if (n) {
  2203.       n[1].f = x;
  2204.       n[2].f = y;
  2205.       n[3].f = z;
  2206.       n[4].f = w;
  2207.    }
  2208.    if (ctx->ExecuteFlag) {
  2209.       (*ctx->Exec.Vertex4f)( ctx, x, y, z, w );
  2210.    }
  2211. }
  2212.  
  2213.  
  2214. void gl_save_Viewport( GLcontext *ctx,
  2215.                        GLint x, GLint y, GLsizei width, GLsizei height )
  2216. {
  2217.    Node *n = alloc_instruction( ctx,  OPCODE_VIEWPORT, 4 );
  2218.    if (n) {
  2219.       n[1].i = x;
  2220.       n[2].i = y;
  2221.       n[3].i = (GLint) width;
  2222.       n[4].i = (GLint) height;
  2223.    }
  2224.    if (ctx->ExecuteFlag) {
  2225.       EXEC(Viewport)( ctx, x, y, width, height );
  2226.    }
  2227. }
  2228.  
  2229.  
  2230. void gl_save_WindowPos4fMESA( GLcontext *ctx,
  2231.                               GLfloat x, GLfloat y, GLfloat z, GLfloat w )
  2232. {
  2233.    Node *n = alloc_instruction( ctx,  OPCODE_WINDOW_POS, 4 );
  2234.    if (n) {
  2235.       n[1].f = x;
  2236.       n[2].f = y;
  2237.       n[3].f = z;
  2238.       n[4].f = w;
  2239.    }
  2240.    if (ctx->ExecuteFlag) {
  2241.       EXEC(WindowPos4fMESA)( ctx, x, y, z, w );
  2242.    }
  2243. }
  2244.  
  2245.  
  2246.  
  2247. /**********************************************************************/
  2248. /*                     Display list execution                         */
  2249. /**********************************************************************/
  2250.  
  2251.  
  2252. /*
  2253.  * Execute a display list.  Note that the ListBase offset must have already
  2254.  * been added before calling this function.  I.e. the list argument is
  2255.  * the absolute list number, not relative to ListBase.
  2256.  * Input:  list - list number in [1..]
  2257.  */
  2258. static void execute_list( GLcontext *ctx, GLuint list )
  2259. {
  2260.    Node *n;
  2261.    GLboolean done;
  2262.    OpCode opcode;
  2263.  
  2264.    if (!gl_IsList(ctx,list))
  2265.       return;
  2266.  
  2267.    ctx->CallDepth++;
  2268.  
  2269.    n = ctx->Shared->List[list-1];
  2270.    done = GL_FALSE;
  2271.    while (!done) {
  2272.       opcode = n[0].opcode;
  2273.  
  2274.       switch (opcode) {
  2275.      /* Frequently called functions: */
  2276.          case OPCODE_VERTEX:
  2277.             (*ctx->Exec.Vertex4f)( ctx, n[1].f, n[2].f, n[3].f, n[4].f );
  2278.             break;
  2279.          case OPCODE_NORMAL:
  2280.             ctx->Current.Normal[0] = n[1].f;
  2281.             ctx->Current.Normal[1] = n[2].f;
  2282.             ctx->Current.Normal[2] = n[3].f;
  2283.             break;
  2284.      case OPCODE_COLOR_4UB:
  2285.             (*ctx->Exec.Color4ub)( ctx, n[1].ub, n[2].ub, n[3].ub, n[4].ub );
  2286.         break;
  2287.      case OPCODE_COLOR_4F:
  2288.             (*ctx->Exec.Color4f)( ctx, n[1].f, n[2].f, n[3].f, n[4].f );
  2289.             break;
  2290.          case OPCODE_INDEX:
  2291.             ctx->Current.Index = n[1].ui;
  2292.             ctx->VB->MonoColor = GL_FALSE;
  2293.             break;
  2294.          case OPCODE_BEGIN:
  2295.             gl_Begin( ctx, n[1].e );
  2296.             break;
  2297.          case OPCODE_END:
  2298.             gl_End( ctx );
  2299.             break;
  2300.      case OPCODE_TEXCOORD:
  2301.         ctx->Current.TexCoord[0] = n[1].f;
  2302.         ctx->Current.TexCoord[1] = n[2].f;
  2303.         ctx->Current.TexCoord[2] = n[3].f;
  2304.         ctx->Current.TexCoord[3] = n[4].f;
  2305.         break;
  2306.  
  2307.      /* Everything Else: */
  2308.          case OPCODE_ACCUM:
  2309.         gl_Accum( ctx, n[1].e, n[2].f );
  2310.         break;
  2311.          case OPCODE_ALPHA_FUNC:
  2312.         gl_AlphaFunc( ctx, n[1].e, n[2].f );
  2313.         break;
  2314.          case OPCODE_BIND_TEXTURE:
  2315.             gl_BindTexture( ctx, n[1].e, n[2].ui );
  2316.             break;
  2317.      case OPCODE_BITMAP:
  2318.         gl_Bitmap( ctx, (GLsizei) n[1].i, (GLsizei) n[2].i,
  2319.                n[3].f, n[4].f,
  2320.                n[5].f, n[6].f,
  2321.                (struct gl_image *) n[7].data );
  2322.         break;
  2323.      case OPCODE_BLEND_COLOR:
  2324.         gl_BlendColor( ctx, n[1].f, n[2].f, n[3].f, n[4].f );
  2325.         break;
  2326.      case OPCODE_BLEND_EQUATION:
  2327.         gl_BlendEquation( ctx, n[1].e );
  2328.         break;
  2329.      case OPCODE_BLEND_FUNC:
  2330.         gl_BlendFunc( ctx, n[1].e, n[2].e );
  2331.         break;
  2332.          case OPCODE_CALL_LIST:
  2333.         /* Generated by glCallList(), don't add ListBase */
  2334.             if (ctx->CallDepth<MAX_LIST_NESTING) {
  2335.                execute_list( ctx, n[1].ui );
  2336.             }
  2337.             break;
  2338.          case OPCODE_CALL_LIST_OFFSET:
  2339.         /* Generated by glCallLists() so we must add ListBase */
  2340.             if (ctx->CallDepth<MAX_LIST_NESTING) {
  2341.                execute_list( ctx, ctx->List.ListBase + n[1].ui );
  2342.             }
  2343.             break;
  2344.      case OPCODE_CLEAR:
  2345.         gl_Clear( ctx, n[1].bf );
  2346.         break;
  2347.      case OPCODE_CLEAR_COLOR:
  2348.         gl_ClearColor( ctx, n[1].f, n[2].f, n[3].f, n[4].f );
  2349.         break;
  2350.      case OPCODE_CLEAR_ACCUM:
  2351.         gl_ClearAccum( ctx, n[1].f, n[2].f, n[3].f, n[4].f );
  2352.         break;
  2353.      case OPCODE_CLEAR_DEPTH:
  2354.         gl_ClearDepth( ctx, (GLclampd) n[1].f );
  2355.         break;
  2356.      case OPCODE_CLEAR_INDEX:
  2357.         gl_ClearIndex( ctx, n[1].ui );
  2358.         break;
  2359.      case OPCODE_CLEAR_STENCIL:
  2360.         gl_ClearStencil( ctx, n[1].i );
  2361.         break;
  2362.          case OPCODE_CLIP_PLANE:
  2363.             {
  2364.                GLfloat equ[4];
  2365.                equ[0] = n[2].f;
  2366.                equ[1] = n[3].f;
  2367.                equ[2] = n[4].f;
  2368.                equ[3] = n[5].f;
  2369.                gl_ClipPlane( ctx, n[1].e, equ );
  2370.             }
  2371.             break;
  2372.      case OPCODE_COLOR_MASK:
  2373.         gl_ColorMask( ctx, n[1].b, n[2].b, n[3].b, n[4].b );
  2374.         break;
  2375.      case OPCODE_COLOR_MATERIAL:
  2376.         gl_ColorMaterial( ctx, n[1].e, n[2].e );
  2377.         break;
  2378.      case OPCODE_COPY_PIXELS:
  2379.         gl_CopyPixels( ctx, n[1].i, n[2].i,
  2380.                (GLsizei) n[3].i, (GLsizei) n[4].i, n[5].e );
  2381.         break;
  2382.          case OPCODE_COPY_TEX_IMAGE1D:
  2383.         gl_CopyTexImage1D( ctx, n[1].e, n[2].i, n[3].e, n[4].i,
  2384.                                n[5].i, n[6].i, n[7].i );
  2385.             break;
  2386.          case OPCODE_COPY_TEX_IMAGE2D:
  2387.         gl_CopyTexImage2D( ctx, n[1].e, n[2].i, n[3].e, n[4].i,
  2388.                                n[5].i, n[6].i, n[7].i, n[8].i );
  2389.             break;
  2390.          case OPCODE_COPY_TEX_SUB_IMAGE1D:
  2391.         gl_CopyTexSubImage1D( ctx, n[1].e, n[2].i, n[3].i, n[4].i,
  2392.                                   n[5].i, n[6].i );
  2393.             break;
  2394.          case OPCODE_COPY_TEX_SUB_IMAGE2D:
  2395.         gl_CopyTexSubImage2D( ctx, n[1].e, n[2].i, n[3].i, n[4].i,
  2396.                                   n[5].i, n[6].i, n[7].i, n[8].i );
  2397.             break;
  2398.          case OPCODE_COPY_TEX_SUB_IMAGE3D:
  2399.             gl_CopyTexSubImage3DEXT( ctx, n[1].e, n[2].i, n[3].i, n[4].i,
  2400.                                      n[5].i, n[6].i, n[7].i, n[8].i , n[9].i);
  2401.             break;
  2402.      case OPCODE_CULL_FACE:
  2403.         gl_CullFace( ctx, n[1].e );
  2404.         break;
  2405.      case OPCODE_DEPTH_FUNC:
  2406.         gl_DepthFunc( ctx, n[1].e );
  2407.         break;
  2408.      case OPCODE_DEPTH_MASK:
  2409.         gl_DepthMask( ctx, n[1].b );
  2410.         break;
  2411.      case OPCODE_DEPTH_RANGE:
  2412.         gl_DepthRange( ctx, (GLclampd) n[1].f, (GLclampd) n[2].f );
  2413.         break;
  2414.      case OPCODE_DISABLE:
  2415.         gl_Disable( ctx, n[1].e );
  2416.         break;
  2417.      case OPCODE_DRAW_BUFFER:
  2418.         gl_DrawBuffer( ctx, n[1].e );
  2419.         break;
  2420.      case OPCODE_DRAW_PIXELS:
  2421.         gl_DrawPixels( ctx, (GLsizei) n[1].i, (GLsizei) n[2].i,
  2422.                n[3].e, n[4].e, n[5].data );
  2423.         break;
  2424.      case OPCODE_EDGE_FLAG:
  2425.             ctx->Current.EdgeFlag = n[1].b;
  2426.             break;
  2427.      case OPCODE_ENABLE:
  2428.         gl_Enable( ctx, n[1].e );
  2429.         break;
  2430.      case OPCODE_EVALCOORD1:
  2431.         gl_EvalCoord1f( ctx, n[1].f );
  2432.         break;
  2433.      case OPCODE_EVALCOORD2:
  2434.         gl_EvalCoord2f( ctx, n[1].f, n[2].f );
  2435.         break;
  2436.      case OPCODE_EVALMESH1:
  2437.         gl_EvalMesh1( ctx, n[1].e, n[2].i, n[3].i );
  2438.         break;
  2439.      case OPCODE_EVALMESH2:
  2440.         gl_EvalMesh2( ctx, n[1].e, n[2].i, n[3].i, n[4].i, n[5].i );
  2441.         break;
  2442.      case OPCODE_EVALPOINT1:
  2443.         gl_EvalPoint1( ctx, n[1].i );
  2444.         break;
  2445.      case OPCODE_EVALPOINT2:
  2446.         gl_EvalPoint2( ctx, n[1].i, n[2].i );
  2447.         break;
  2448.      case OPCODE_FOG:
  2449.         {
  2450.            GLfloat p[4];
  2451.            p[0] = n[2].f;
  2452.            p[1] = n[3].f;
  2453.            p[2] = n[4].f;
  2454.            p[3] = n[5].f;
  2455.            gl_Fogfv( ctx, n[1].e, p );
  2456.         }
  2457.         break;
  2458.      case OPCODE_FRONT_FACE:
  2459.         gl_FrontFace( ctx, n[1].e );
  2460.         break;
  2461.      case OPCODE_HINT:
  2462.         gl_Hint( ctx, n[1].e, n[2].e );
  2463.         break;
  2464.      case OPCODE_INDEX_MASK:
  2465.         gl_IndexMask( ctx, n[1].ui );
  2466.         break;
  2467.      case OPCODE_INIT_NAMES:
  2468.         gl_InitNames( ctx );
  2469.         break;
  2470.          case OPCODE_LIGHT:
  2471.         {
  2472.            GLfloat p[4];
  2473.            p[0] = n[3].f;
  2474.            p[1] = n[4].f;
  2475.            p[2] = n[5].f;
  2476.            p[3] = n[6].f;
  2477.            gl_Lightfv( ctx, n[1].e, n[2].e, p, 4 );
  2478.         }
  2479.         break;
  2480.          case OPCODE_LIGHT_MODEL:
  2481.         {
  2482.            GLfloat p[4];
  2483.            p[0] = n[2].f;
  2484.            p[1] = n[3].f;
  2485.            p[2] = n[4].f;
  2486.            p[3] = n[5].f;
  2487.            gl_LightModelfv( ctx, n[1].e, p );
  2488.         }
  2489.         break;
  2490.      case OPCODE_LINE_STIPPLE:
  2491.         gl_LineStipple( ctx, n[1].i, n[2].us );
  2492.         break;
  2493.      case OPCODE_LINE_WIDTH:
  2494.         gl_LineWidth( ctx, n[1].f );
  2495.         break;
  2496.      case OPCODE_LIST_BASE:
  2497.         gl_ListBase( ctx, n[1].ui );
  2498.         break;
  2499.      case OPCODE_LOAD_MATRIX:
  2500.         if (sizeof(Node)==sizeof(GLfloat)) {
  2501.            gl_LoadMatrixf( ctx, &n[1].f );
  2502.         }
  2503.         else {
  2504.            GLfloat m[16];
  2505.            GLuint i;
  2506.            for (i=0;i<16;i++) {
  2507.           m[i] = n[1+i].f;
  2508.            }
  2509.            gl_LoadMatrixf( ctx, m );
  2510.         }
  2511.         break;
  2512.      case OPCODE_LOAD_NAME:
  2513.         gl_LoadName( ctx, n[1].ui );
  2514.         break;
  2515.      case OPCODE_LOGIC_OP:
  2516.         gl_LogicOp( ctx, n[1].e );
  2517.         break;
  2518.      case OPCODE_MAP1:
  2519.         gl_Map1f( ctx, n[1].e, n[2].f, n[3].f,
  2520.                       n[4].i, n[5].i, (GLfloat *) n[6].data, GL_TRUE );
  2521.         break;
  2522.      case OPCODE_MAP2:
  2523.         gl_Map2f( ctx, n[1].e,
  2524.                       n[2].f, n[3].f,  /* u1, u2 */
  2525.               n[6].i, n[8].i,  /* ustride, uorder */
  2526.               n[4].f, n[5].f,  /* v1, v2 */
  2527.               n[7].i, n[9].i,  /* vstride, vorder */
  2528.               (GLfloat *) n[10].data,
  2529.                       GL_TRUE);
  2530.         break;
  2531.      case OPCODE_MAPGRID1:
  2532.         gl_MapGrid1f( ctx, n[1].i, n[2].f, n[3].f );
  2533.         break;
  2534.      case OPCODE_MAPGRID2:
  2535.         gl_MapGrid2f( ctx, n[1].i, n[2].f, n[3].f, n[4].i, n[5].f, n[6].f);
  2536.         break;
  2537.      case OPCODE_MATERIAL:
  2538.         {
  2539.            GLfloat params[4];
  2540.            params[0] = n[3].f;
  2541.            params[1] = n[4].f;
  2542.            params[2] = n[5].f;
  2543.            params[3] = n[6].f;
  2544.            gl_Materialfv( ctx, n[1].e, n[2].e, params );
  2545.         }
  2546.         break;
  2547.          case OPCODE_MATRIX_MODE:
  2548.             gl_MatrixMode( ctx, n[1].e );
  2549.             break;
  2550.      case OPCODE_MULT_MATRIX:
  2551.         if (sizeof(Node)==sizeof(GLfloat)) {
  2552.            gl_MultMatrixf( ctx, &n[1].f );
  2553.         }
  2554.         else {
  2555.            GLfloat m[16];
  2556.            GLuint i;
  2557.            for (i=0;i<16;i++) {
  2558.           m[i] = n[1+i].f;
  2559.            }
  2560.            gl_MultMatrixf( ctx, m );
  2561.         }
  2562.         break;
  2563.      case OPCODE_PASSTHROUGH:
  2564.         gl_PassThrough( ctx, n[1].f );
  2565.         break;
  2566.      case OPCODE_PIXEL_MAP:
  2567.         gl_PixelMapfv( ctx, n[1].e, n[2].i, (GLfloat *) n[3].data );
  2568.         break;
  2569.      case OPCODE_PIXEL_TRANSFER:
  2570.         gl_PixelTransferf( ctx, n[1].e, n[2].f );
  2571.         break;
  2572.      case OPCODE_PIXEL_ZOOM:
  2573.         gl_PixelZoom( ctx, n[1].f, n[2].f );
  2574.         break;
  2575.      case OPCODE_POINTSIZE:
  2576.         gl_PointSize( ctx, n[1].f );
  2577.         break;
  2578.      case OPCODE_POLYGON_MODE:
  2579.         gl_PolygonMode( ctx, n[1].e, n[2].e );
  2580.         break;
  2581.      case OPCODE_POLYGON_STIPPLE:
  2582.         gl_PolygonStipple( ctx, (GLubyte *) n[1].data );
  2583.         break;
  2584.      case OPCODE_POLYGON_OFFSET:
  2585.         gl_PolygonOffset( ctx, n[1].f, n[2].f );
  2586.         break;
  2587.      case OPCODE_POP_ATTRIB:
  2588.         gl_PopAttrib( ctx );
  2589.         break;
  2590.      case OPCODE_POP_MATRIX:
  2591.         gl_PopMatrix( ctx );
  2592.         break;
  2593.      case OPCODE_POP_NAME:
  2594.         gl_PopName( ctx );
  2595.         break;
  2596.      case OPCODE_PRIORITIZE_TEXTURE:
  2597.             gl_PrioritizeTextures( ctx, 1, &n[1].ui, &n[2].f );
  2598.         break;
  2599.      case OPCODE_PUSH_ATTRIB:
  2600.         gl_PushAttrib( ctx, n[1].bf );
  2601.         break;
  2602.      case OPCODE_PUSH_MATRIX:
  2603.         gl_PushMatrix( ctx );
  2604.         break;
  2605.      case OPCODE_PUSH_NAME:
  2606.         gl_PushName( ctx, n[1].ui );
  2607.         break;
  2608.      case OPCODE_RASTER_POS:
  2609.             gl_RasterPos4f( ctx, n[1].f, n[2].f, n[3].f, n[4].f );
  2610.         break;
  2611.      case OPCODE_READ_BUFFER:
  2612.         gl_ReadBuffer( ctx, n[1].e );
  2613.         break;
  2614.          case OPCODE_SCALE:
  2615.             gl_Scalef( ctx, n[1].f, n[2].f, n[3].f );
  2616.             break;
  2617.      case OPCODE_SCISSOR:
  2618.         gl_Scissor( ctx, n[1].i, n[2].i, n[3].i, n[4].i );
  2619.         break;
  2620.      case OPCODE_SHADE_MODEL:
  2621.         gl_ShadeModel( ctx, n[1].e );
  2622.         break;
  2623.      case OPCODE_STENCIL_FUNC:
  2624.         gl_StencilFunc( ctx, n[1].e, n[2].i, n[3].ui );
  2625.         break;
  2626.      case OPCODE_STENCIL_MASK:
  2627.         gl_StencilMask( ctx, n[1].ui );
  2628.         break;
  2629.      case OPCODE_STENCIL_OP:
  2630.         gl_StencilOp( ctx, n[1].e, n[2].e, n[3].e );
  2631.         break;
  2632.          case OPCODE_TEXENV:
  2633.             {
  2634.                GLfloat params[4];
  2635.                params[0] = n[3].f;
  2636.                params[1] = n[4].f;
  2637.                params[2] = n[5].f;
  2638.                params[3] = n[6].f;
  2639.                gl_TexEnvfv( ctx, n[1].e, n[2].e, params );
  2640.             }
  2641.             break;
  2642.          case OPCODE_TEXGEN:
  2643.             {
  2644.                GLfloat params[4];
  2645.                params[0] = n[3].f;
  2646.                params[1] = n[4].f;
  2647.                params[2] = n[5].f;
  2648.                params[3] = n[6].f;
  2649.                gl_TexGenfv( ctx, n[1].e, n[2].e, params );
  2650.             }
  2651.             break;
  2652.          case OPCODE_TEXPARAMETER:
  2653.             {
  2654.                GLfloat params[4];
  2655.                params[0] = n[3].f;
  2656.                params[1] = n[4].f;
  2657.                params[2] = n[5].f;
  2658.                params[3] = n[6].f;
  2659.                gl_TexParameterfv( ctx, n[1].e, n[2].e, params );
  2660.             }
  2661.             break;
  2662.      case OPCODE_TEX_IMAGE1D:
  2663.         gl_TexImage1D( ctx,
  2664.                            n[1].e, /* target */
  2665.                            n[2].i, /* level */
  2666.                            n[3].i, /* components */
  2667.                            n[4].i, /* width */
  2668.                            n[5].e, /* border */
  2669.                            n[6].e, /* format */
  2670.                            n[7].e, /* type */
  2671.                            n[8].data );
  2672.         break;
  2673.      case OPCODE_TEX_IMAGE2D:
  2674.         gl_TexImage2D( ctx,
  2675.                            n[1].e, /* target */
  2676.                            n[2].i, /* level */
  2677.                            n[3].i, /* components */
  2678.                            n[4].i, /* width */
  2679.                            n[5].i, /* height */
  2680.                            n[6].e, /* border */
  2681.                            n[7].e, /* format */
  2682.                            n[8].e, /* type */
  2683.                            n[9].data );
  2684.         break;
  2685.          case OPCODE_TEX_IMAGE3D:
  2686.             gl_TexImage3DEXT( ctx,
  2687.                               n[1].e, /* target */
  2688.                               n[2].i, /* level */
  2689.                               n[3].i, /* components */
  2690.                               n[4].i, /* width */
  2691.                               n[5].i, /* height */
  2692.                               n[6].i, /* depth  */
  2693.                               n[7].e, /* border */
  2694.                               n[8].e, /* format */
  2695.                               n[9].e, /* type */
  2696.                               n[10].data );
  2697.             break;
  2698.          case OPCODE_TEX_SUB_IMAGE1D:
  2699.             gl_TexSubImage1D( ctx, n[1].e, n[2].i, n[3].i, n[4].i, n[5].e,
  2700.                               n[6].e, (struct gl_image *) n[7].data );
  2701.             break;
  2702.          case OPCODE_TEX_SUB_IMAGE2D:
  2703.             gl_TexSubImage2D( ctx, n[1].e, n[2].i, n[3].i, n[4].i, n[5].e,
  2704.                               n[6].i, n[7].e, n[8].e,
  2705.                               (struct gl_image *) n[9].data );
  2706.             break;
  2707.          case OPCODE_TEX_SUB_IMAGE3D:
  2708.             gl_TexSubImage3DEXT( ctx, n[1].e, n[2].i, n[3].i, n[4].i, n[5].i,
  2709.                                  n[6].i, n[7].i, n[8].i, n[9].e, n[10].e,
  2710.                                  (struct gl_image *) n[11].data );
  2711.             break;
  2712.          case OPCODE_TRANSLATE:
  2713.             gl_Translatef( ctx, n[1].f, n[2].f, n[3].f );
  2714.             break;
  2715.      case OPCODE_VIEWPORT:
  2716.         gl_Viewport( ctx,
  2717.                          n[1].i, n[2].i, (GLsizei) n[3].i, (GLsizei) n[4].i );
  2718.         break;
  2719.      case OPCODE_WINDOW_POS:
  2720.             gl_WindowPos4fMESA( ctx, n[1].f, n[2].f, n[3].f, n[4].f );
  2721.         break;
  2722.      case OPCODE_CONTINUE:
  2723.         n = (Node *) n[1].next;
  2724.         break;
  2725.      case OPCODE_END_OF_LIST:
  2726.         done = GL_TRUE;
  2727.         break;
  2728.      default:
  2729.             {
  2730.                char msg[1000];
  2731.                sprintf(msg, "Error in execute_list: opcode=%d", (int) opcode);
  2732.                gl_problem( ctx, msg );
  2733.             }
  2734.             done = GL_TRUE;
  2735.       }
  2736.  
  2737.       /* increment n to point to next compiled command */
  2738.       if (opcode!=OPCODE_CONTINUE) {
  2739.      n += InstSize[opcode];
  2740.       }
  2741.  
  2742.    }
  2743.    ctx->CallDepth--;
  2744. }
  2745.  
  2746.  
  2747.  
  2748. /**********************************************************************/
  2749. /*                           GL functions                             */
  2750. /**********************************************************************/
  2751.  
  2752.  
  2753.  
  2754. /*
  2755.  * Test if a display list number is valid.
  2756.  */
  2757. GLboolean gl_IsList( GLcontext *ctx, GLuint list )
  2758. {
  2759.    if (list>0 && list<=MAX_DISPLAYLISTS && ctx->Shared->List[list-1]) {
  2760.       return GL_TRUE;
  2761.    }
  2762.    else {
  2763.       return GL_FALSE;
  2764.    }
  2765. }
  2766.  
  2767.  
  2768.  
  2769. /*
  2770.  * Delete a sequence of consecutive display lists.
  2771.  */
  2772. void gl_DeleteLists( GLcontext *ctx, GLuint list, GLsizei range )
  2773. {
  2774.    GLuint i;
  2775.  
  2776.    if (INSIDE_BEGIN_END(ctx)) {
  2777.       gl_error( ctx, GL_INVALID_OPERATION, "glDeleteLists" );
  2778.       return;
  2779.    }
  2780.    if (range<0) {
  2781.       gl_error( ctx, GL_INVALID_VALUE, "glDeleteLists" );
  2782.       return;
  2783.    }
  2784.    for (i=list;i<list+range;i++) {
  2785.       if (i<=MAX_DISPLAYLISTS && ctx->Shared->List[i-1]) {
  2786.          destroy_list( ctx, i-1 );
  2787.          ctx->Shared->List[i-1] = NULL;
  2788.       }
  2789.    }
  2790. }
  2791.  
  2792.  
  2793.  
  2794. /*
  2795.  * Return a display list number, n, such that lists n through n+range-1
  2796.  * are free.
  2797.  */
  2798. GLuint gl_GenLists( GLcontext *ctx, GLsizei range )
  2799. {
  2800.    GLuint i, freecount;
  2801.  
  2802.    if (INSIDE_BEGIN_END(ctx)) {
  2803.       gl_error( ctx, GL_INVALID_OPERATION, "glGenLists" );
  2804.       return 0;
  2805.    }
  2806.    if (range<0) {
  2807.       gl_error( ctx, GL_INVALID_VALUE, "glGenLists" );
  2808.       return 0;
  2809.    }
  2810.    if (range==0) {
  2811.       return 0;
  2812.    }
  2813.  
  2814.    i = 0;
  2815.    freecount = 0;
  2816.    for (i=0; i<MAX_DISPLAYLISTS; i++ ) {
  2817.       if (ctx->Shared->List[i]==NULL) {
  2818.          freecount++;
  2819.          if (freecount==range) {
  2820.         /* We found 'range' consecutive free lists. */
  2821.             /* Now reserve the IDs with empty display lists. */
  2822.         GLuint k;
  2823.         GLuint n = i-range+2;
  2824.         for (k=n;k<n+range;k++) {
  2825.            ctx->Shared->List[k-1] = make_empty_list();
  2826.         }
  2827.             return n;
  2828.          }
  2829.       }
  2830.       else {
  2831.          freecount = 0;
  2832.       }
  2833.    }
  2834.    return 0;
  2835. }
  2836.  
  2837.  
  2838.  
  2839. /*
  2840.  * Begin a new display list.
  2841.  */
  2842. void gl_NewList( GLcontext *ctx, GLuint list, GLenum mode )
  2843. {
  2844.    if (INSIDE_BEGIN_END(ctx)) {
  2845.       gl_error( ctx, GL_INVALID_OPERATION, "glNewList" );
  2846.       return;
  2847.    }
  2848.    if (list==0 || list>MAX_DISPLAYLISTS) {
  2849.       gl_error( ctx, GL_INVALID_VALUE, "glNewList" );
  2850.       return;
  2851.    }
  2852.    if (mode!=GL_COMPILE && mode!=GL_COMPILE_AND_EXECUTE) {
  2853.       gl_error( ctx, GL_INVALID_ENUM, "glNewList" );
  2854.       return;
  2855.    }
  2856.    if (CurrentListPtr) {
  2857.       /* already compiling a display list */
  2858.       gl_error( ctx, GL_INVALID_OPERATION, "glNewList" );
  2859.       return;
  2860.    }
  2861.  
  2862.    /* Allocate new display list */
  2863.    CurrentListNum = list;
  2864.    CurrentListPtr = CurrentBlock = (Node *) malloc( sizeof(Node) * BLOCK_SIZE );
  2865.    CurrentPos = 0;
  2866.  
  2867.    ctx->CompileFlag = GL_TRUE;
  2868.    if (mode==GL_COMPILE) {
  2869.       ctx->ExecuteFlag = GL_FALSE;
  2870.    }
  2871.    else {
  2872.       /* Compile and execute */
  2873.       ctx->ExecuteFlag = GL_TRUE;
  2874.    }
  2875.  
  2876.    ctx->API = ctx->Save;  /* Switch the API function pointers */
  2877. }
  2878.  
  2879.  
  2880.  
  2881. /*
  2882.  * End definition of current display list.
  2883.  */
  2884. void gl_EndList( GLcontext *ctx )
  2885. {
  2886.    Node *n;
  2887.  
  2888.    /* Check that a list is under construction */
  2889.    if (!CurrentListPtr) {
  2890.       gl_error( ctx, GL_INVALID_OPERATION, "glEndList" );
  2891.       return;
  2892.    }
  2893.  
  2894.    n = alloc_instruction( ctx, OPCODE_END_OF_LIST, 0 );
  2895.  
  2896.    /* Install the list */
  2897.    if (ctx->Shared->List[CurrentListNum-1]) {
  2898.       destroy_list( ctx, CurrentListNum-1 );
  2899.    }
  2900.    ctx->Shared->List[CurrentListNum-1] = CurrentListPtr;
  2901.  
  2902.    CurrentListNum = 0;
  2903.    CurrentListPtr = NULL;
  2904.    ctx->ExecuteFlag = GL_TRUE;
  2905.    ctx->CompileFlag = GL_FALSE;
  2906.  
  2907.    ctx->API = ctx->Exec;   /* Switch the API function pointers */
  2908. }
  2909.  
  2910.  
  2911.  
  2912. void gl_CallList( GLcontext *ctx, GLuint list )
  2913. {
  2914.    /* VERY IMPORTANT:  Save the CompileFlag status, turn it off, */
  2915.    /* execute the display list, and restore the CompileFlag. */
  2916.    GLboolean save_compile_flag;
  2917.    save_compile_flag = ctx->CompileFlag;
  2918.    ctx->CompileFlag = GL_FALSE;
  2919.    execute_list( ctx, list );
  2920.    ctx->CompileFlag = save_compile_flag;
  2921. }
  2922.  
  2923.  
  2924.  
  2925. /*
  2926.  * Execute glCallLists:  call multiple display lists.
  2927.  */
  2928. void gl_CallLists( GLcontext *ctx,
  2929.                    GLsizei n, GLenum type, const GLvoid *lists )
  2930. {
  2931.    GLuint i, list;
  2932.    GLboolean save_compile_flag;
  2933.  
  2934.    /* Save the CompileFlag status, turn it off, execute display list,
  2935.     * and restore the CompileFlag.
  2936.     */
  2937.    save_compile_flag = ctx->CompileFlag;
  2938.    ctx->CompileFlag = GL_FALSE;
  2939.  
  2940.    for (i=0;i<n;i++) {
  2941.       list = translate_id( i, type, lists );
  2942.       execute_list( ctx, ctx->List.ListBase + list );
  2943.    }
  2944.  
  2945.    ctx->CompileFlag = save_compile_flag;
  2946. }
  2947.  
  2948.  
  2949.  
  2950. /*
  2951.  * Set the offset added to list numbers in glCallLists.
  2952.  */
  2953. void gl_ListBase( GLcontext *ctx, GLuint base )
  2954. {
  2955.    if (INSIDE_BEGIN_END(ctx)) {
  2956.       gl_error( ctx, GL_INVALID_OPERATION, "glListBase" );
  2957.       return;
  2958.    }
  2959.    ctx->List.ListBase = base;
  2960. }
  2961.  
  2962.  
  2963.  
  2964.  
  2965. /***
  2966.  *** Debugging code
  2967.  ***/
  2968.  
  2969. static char tmp[1000];
  2970.  
  2971. static char *enum_string( GLenum k )
  2972. {
  2973.    /* TODO: Add many more constant/string entries */
  2974.    switch (k) {
  2975.       case GL_POINTS:        return "GL_POINTS";
  2976.       case GL_LINES:        return "GL_LINES";
  2977.       case GL_LINE_STRIP:    return "GL_LINE_STRIP";
  2978.       case GL_LINE_LOOP:    return "GL_LINE_LOOP";
  2979.       case GL_TRIANGLES:    return "GL_TRIANGLES";
  2980.       case GL_TRIANGLE_STRIP:    return "GL_TRIANGLE_STRIP";
  2981.       case GL_TRIANGLE_FAN:    return "GL_TRIANGLE_FAN";
  2982.       case GL_QUADS:        return "GL_QUADS";
  2983.       case GL_QUAD_STRIP:    return "GL_QUAD_STRIP";
  2984.       case GL_POLYGON:        return "GL_POLYGON";
  2985.       case GL_FRONT:        return "GL_FRONT";
  2986.       case GL_BACK:        return "GL_BACK";
  2987.       case GL_FRONT_AND_BACK:    return "GL_FRONT_AND_BACK";
  2988.       case GL_AMBIENT:        return "GL_AMBIENT";
  2989.       case GL_DIFFUSE:        return "GL_DIFFUSE";
  2990.       case GL_SPECULAR:        return "GL_SPECULAR";
  2991.       case GL_SHININESS:    return "GL_SHININESS";
  2992.       default:
  2993.          sprintf(tmp,"%X", k);
  2994.          return tmp;
  2995.    }
  2996. }
  2997.  
  2998.  
  2999. /*
  3000.  * Print the commands in a display list.  For debugging only.
  3001.  * TODO: many commands aren't handled yet.
  3002.  */
  3003. static void print_list( GLcontext *ctx, FILE *f, GLuint list )
  3004. {
  3005.    Node *n;
  3006.    GLboolean done;
  3007.    OpCode opcode;
  3008.  
  3009.    if (!glIsList(list)) {
  3010.       fprintf(f,"%d is not a display list ID\n",list);
  3011.       return;
  3012.    }
  3013.  
  3014.    n = ctx->Shared->List[list-1];
  3015.  
  3016.    fprintf( f, "START-LIST %d, address %p\n", list, (void*)n );
  3017.  
  3018.    done = GL_FALSE;
  3019.    while (!done) {
  3020.       opcode = n[0].opcode;
  3021.  
  3022.       switch (opcode) {
  3023.          case OPCODE_ACCUM:
  3024.             fprintf(f,"accum %d %g\n", n[1].e, n[2].f );
  3025.         break;
  3026.          case OPCODE_BEGIN:
  3027.             fprintf(f,"Begin %s\n", enum_string(n[1].e) );
  3028.             break;
  3029.      case OPCODE_BITMAP:
  3030.             fprintf(f,"Bitmap %d %d %g %g %g %g %p\n", n[1].i, n[2].i,
  3031.                n[3].f, n[4].f, n[5].f, n[6].f, (void *) n[7].data );
  3032.         break;
  3033.          case OPCODE_CALL_LIST:
  3034.             fprintf(f,"CallList %d\n", n[1].ui );
  3035.             break;
  3036.          case OPCODE_CALL_LIST_OFFSET:
  3037.             fprintf(f,"CallList %d + offset %d = %d\n", n[1].ui,
  3038.                     ctx->List.ListBase, ctx->List.ListBase + n[1].ui );
  3039.             break;
  3040.      case OPCODE_COLOR_4F:
  3041.             fprintf(f,"Color4f %g %g %g %g\n", n[1].f, n[2].f, n[3].f, n[4].f);
  3042.         break;
  3043.      case OPCODE_COLOR_4UB:
  3044.             fprintf(f,"Color4ub %d %d %d %d\n", n[1].ub, n[2].ub,
  3045.                                                 n[3].ub, n[4].ub );
  3046.         break;
  3047.      case OPCODE_DISABLE:
  3048.             fprintf(f,"Disable %s\n", enum_string(n[1].e));
  3049.         break;
  3050.      case OPCODE_ENABLE:
  3051.             fprintf(f,"Enable %s\n", enum_string(n[1].e));
  3052.         break;
  3053.          case OPCODE_END:
  3054.             fprintf(f,"End\n");
  3055.             break;
  3056.          case OPCODE_INDEX:
  3057.             fprintf(f,"Index %d\n", n[1].ui );
  3058.             break;
  3059.      case OPCODE_LINE_STIPPLE:
  3060.         fprintf(f,"LineStipple %d %x\n", n[1].i, (int) n[2].us );
  3061.         break;
  3062.      case OPCODE_LOAD_MATRIX:
  3063.             fprintf(f,"LoadMatrix (or LoadIdentity)\n");
  3064.             fprintf(f,"  %8f %8f %8f %8f\n", n[1].f, n[5].f,  n[9].f, n[13].f);
  3065.             fprintf(f,"  %8f %8f %8f %8f\n", n[2].f, n[6].f, n[10].f, n[14].f);
  3066.             fprintf(f,"  %8f %8f %8f %8f\n", n[3].f, n[7].f, n[11].f, n[15].f);
  3067.             fprintf(f,"  %8f %8f %8f %8f\n", n[4].f, n[8].f, n[12].f, n[16].f);
  3068.         break;
  3069.      case OPCODE_MATERIAL:
  3070.             fprintf(f,"Material %s %s %g %g %g %g\n", enum_string(n[1].e),
  3071.                     enum_string(n[2].e), n[3].f, n[4].f, n[5].f, n[6].f );
  3072.             break;
  3073.      case OPCODE_MULT_MATRIX:
  3074.             fprintf(f,"MultMatrix (or Rotate)\n");
  3075.             fprintf(f,"  %8f %8f %8f %8f\n", n[1].f, n[5].f,  n[9].f, n[13].f);
  3076.             fprintf(f,"  %8f %8f %8f %8f\n", n[2].f, n[6].f, n[10].f, n[14].f);
  3077.             fprintf(f,"  %8f %8f %8f %8f\n", n[3].f, n[7].f, n[11].f, n[15].f);
  3078.             fprintf(f,"  %8f %8f %8f %8f\n", n[4].f, n[8].f, n[12].f, n[16].f);
  3079.         break;
  3080.          case OPCODE_NORMAL:
  3081.             fprintf(f,"Normal %g %g %g\n", n[1].f, n[2].f, n[3].f );
  3082.             break;
  3083.      case OPCODE_POP_ATTRIB:
  3084.             fprintf(f,"PopAttrib\n");
  3085.         break;
  3086.      case OPCODE_POP_MATRIX:
  3087.             fprintf(f,"PopMatrix\n");
  3088.         break;
  3089.      case OPCODE_POP_NAME:
  3090.             fprintf(f,"PopName\n");
  3091.         break;
  3092.      case OPCODE_PUSH_ATTRIB:
  3093.             fprintf(f,"PushAttrib %x\n", n[1].bf );
  3094.         break;
  3095.      case OPCODE_PUSH_MATRIX:
  3096.             fprintf(f,"PushMatrix\n");
  3097.         break;
  3098.      case OPCODE_PUSH_NAME:
  3099.             fprintf(f,"PushName %d\n", n[1].ui );
  3100.         break;
  3101.      case OPCODE_RASTER_POS:
  3102.             fprintf(f,"RasterPos %g %g %g %g\n", n[1].f, n[2].f,n[3].f,n[4].f);
  3103.         break;
  3104.          case OPCODE_SCALE:
  3105.             fprintf(f,"Scale %g %g %g\n", n[1].f, n[2].f, n[3].f );
  3106.             break;
  3107.      case OPCODE_TEXCOORD:
  3108.             fprintf(f,"Texcoord %g %g %g %g\n", n[1].f, n[2].f, n[3].f,n[4].f);
  3109.         break;
  3110.          case OPCODE_TRANSLATE:
  3111.             fprintf(f,"Translate %g %g %g\n", n[1].f, n[2].f, n[3].f );
  3112.             break;
  3113.          case OPCODE_VERTEX:
  3114.             fprintf(f,"Vertex %g %g %g %g\n", n[1].f, n[2].f, n[3].f, n[4].f );
  3115.             break;
  3116.  
  3117.      /*
  3118.       * meta opcodes/commands
  3119.       */
  3120.      case OPCODE_CONTINUE:
  3121.             fprintf(f,"DISPLAY-LIST-CONTINUE\n");
  3122.         n = (Node *) n[1].next;
  3123.         break;
  3124.      case OPCODE_END_OF_LIST:
  3125.             fprintf(f,"END-LIST %d\n", list);
  3126.         done = GL_TRUE;
  3127.         break;
  3128.          default:
  3129.             if (opcode < 0 || opcode > OPCODE_END_OF_LIST) {
  3130.                fprintf(f,"ERROR IN DISPLAY LIST: opcode = %d, address = %p\n",
  3131.                        opcode, (void*) n);
  3132.                return;
  3133.             }
  3134.             else {
  3135.                fprintf(f,"command %d, %d operands\n",opcode,InstSize[opcode]);
  3136.             }
  3137.       }
  3138.  
  3139.       /* increment n to point to next compiled command */
  3140.       if (opcode!=OPCODE_CONTINUE) {
  3141.      n += InstSize[opcode];
  3142.       }
  3143.  
  3144.    }
  3145. }
  3146.  
  3147.  
  3148.  
  3149. /*
  3150.  * Clients may call this function to help debug display list problems.
  3151.  * This function is _ONLY_FOR_DEBUGGING_PURPOSES_.  It may be removed,
  3152.  * changed, or break in the future without notice.
  3153.  */
  3154. void mesa_print_display_list( GLuint list )
  3155. {
  3156.    GLcontext *ctx;
  3157. #ifdef MULTI_THREADING
  3158.    ctx = gl_get_thread_context();
  3159. #else
  3160.    ctx = CC;
  3161. #endif
  3162.    print_list( ctx, stdout, list );
  3163. }
  3164.